Deploy STM32 family on Zephyr
Erwan Gouriou
ENGINEERS
AND DEVICES
WORKING
TOGETHER
Plan
● A glance at STM32 ecosystem
● STM32 porting on Zephyr
● Device tree concept applied to STM32 family
● What’s next for STM32 in Zephyr
ENGINEERS
AND DEVICES
WORKING
TOGETHER
A glance at STM32 Ecosystem
ENGINEERS AND DEVICES
WORKING TOGETHER
Quick outlook on STM32 SoC family
● Cortex-M based MCUs
● More than 700 SoC part numbers
● Split in 10 series
● STM32 family keeps evolving and
more to come…
● http://www.st.com/en/microcontrollers
/stm32-32-bit-arm-cortex-mcus.html
● «MCU finder» utility:
●http://www.st.com/en/development-tool
s/st-mcu-finder.html
ENGINEERS AND DEVICES
WORKING TOGETHER
STM32 MCU naming convention
STM32 F 0 3
Family
STM32 Cortex 32bit
Lines :
0 Value
1 Access
2 USB
3 ---
4 ---
5 OTG
6 LCD/TFT+OTG
7 Ethernet
8 Regulator off
9 LCD TFT
Sub-Lines:
0 ---
1 ---
2 ---
3 --- Small die
4 ---
5 --- Medium die
6 ---
7 --- Big die
8 ---
9 --- High integration
Product type
F Foundation
L Ultra-low-power
H High performance
A higher number means
a richer configuration!
1 R
Flash size (Kbytes) :
4 16
6 32
8 64
B 128
C 256
D 384
E 512
F 768
G 1024
H 1536
I 2048
B
Package:
F 20 pins
G 28 pins
K 32 pins
T 36 pins
S 44 pins
C 48 pins
R 64, 66 pins
M 80 pins
O 90 pins
Series Number:
0 Cortex-M0
1 Cortex-M3
2 Cortex-M3
3 Cortex-M4
4 Cortex-M4
7 Cortex-M7
ENGINEERS AND DEVICES
WORKING TOGETHER
Focus on B-L475E-IOT01A (disco_l475_iot1)
STM32L475 SoC:
Low power, 80MHz
1Mbit flash
128 kRAM
Inventek ISM43362-M3G:
Wi-Fi Module
M24SR: NFC Module
VLX53L0X: Time of Flight
and gesture recognition
HTS221: Humidity and
Temperature
USB OTG Arduino V3 connector
SPSGRF:Sub-GHz Module
64MBit Quad-SPI Flash
MP34DT01:
Omnidirectionnal mic (x2)
SPBTLE-RF: BT Module
LIS3MDL: 3-Axis
magnetometer
LPS22HB: Barometer
LMS6DSL: 3D
accelerometer and
gyroscope
Connectivity
Sensing
MCU Status:
Upstreamed
In progress
ENGINEERS AND DEVICES
WORKING TOGETHER
STM32Cube: Embedded Software for STM32
http://www.st.com/en/embedded-software/stm32cube-embedded-software.html
ENGINEERS AND DEVICES
WORKING TOGETHER
STM32Cube APIs: HAL vs LL
● HAL (Hardware Abstraction Layers):
○ High level and functional abstraction
○ 100% coverage of all peripherals
○ Good match for complex drivers such as USB, Ethernet, ..
○ Higher portability => bigger software footprints, more time running adaptation code => Less optimized
● LL (Low-Layers):
○ Light-weight, optimized, expert oriented set of APIs designed for both performance and runtime
efficiency
○ Register level access library. Do not use global variables. Atomic operations
○ Fit for most zephyr drivers and allows to build stm32 generic lightweight drivers.
○ Perfect fit for “simple IPs” drivers
● HAL/LL could be used together in a single driver
ENGINEERS AND DEVICES
WORKING TOGETHER
Main STM32Cube benefit: Abstraction
● Usual prejudices on HAL:
○ Size, sub optimization
○ coding style…
● Usual pro-HAL arguments are:
○ Avoid re-inventing the wheel, allow to save time…
○ Thoroughly maintained and validated, help developing more mature drivers
● Abstraction capability breaks silos between series/re-inforces cooperation
○ Focussed competencies: more users and more reviewers on a single driver
○ More minds: more performant drivers
○ Reduce work duplication: faster increase of driver support
○ Less code: maintenance effort is reduced.
ENGINEERS
AND DEVICES
WORKING
TOGETHER
STM32 porting on Zephyr
ENGINEERS AND DEVICES
WORKING TOGETHER
STM32Cube: Integration in Zephyr
ext/hal/st/stm32cubearch/arm/soc/st_stm32/
○ stm32f1xx/
○ stm32f3xx/
■ drivers/ (HAL and LL)
● include/
● src/
■ soc / (CMSIS Files: stm32f303x8.h)
■ README
○ stm32f4xx
○ …
● Maintained and updated at each Zephyr DV (at least)
● STM32Cube, as an external library, should not be modified
● But: in case of genuine STM32Cube bug:
○ Report to STM32Cube Zephyr maintainer (issue will be raised in ST bugtracker)
○ Fix issue in a separate PR. Document README (ST Bug ref / Impacted files)
○ Reported issues are taken into account / Don’t hesitate to report issues!
ENGINEERS AND DEVICES
WORKING TOGETHER
How to: Introduce a new LL/HAL based driver
● HAL or LL?
○ Driver complexity?
○ Acceptable footprint?
○ Supported features?
○ Validation effort?
● Maximize code reuse
○ Use CMSIS defines
● Adapt code structure to IP diversity
○ Factorise as much as possible. Examples =>
Small variations within family:
spi_ll_stm32.c (use of #ifdef’s)
2 different IPs in whole family (v1/v2):
i2c_ll_stm32.c
i2c_ll_stm32_v1.c (I2C V1: F1/F2/F4/L1)
i2c_ll_stm32_v2.c (I2C V2: F0/F3/F7/L4)
Important heterogeneity:
stm32_ll_clock.c
stm32f1x_ll_clock.c (F1 series)
stm32f3x_ll_clock.c (F3 series)
…
● Lot of HAL/LL examples in stm32cube packages
● Community support on https://community.st.com
ENGINEERS AND DEVICES
WORKING TOGETHER
STM32 MCU porting: Minimize code duplication
● Code organized per series
● In each series:
○ MCUspecific info (number of IRQ, SoC refence) is
stored under Kconfig.defconfig.stm32yyyxx
○ Series Kconfig are defined
● New: “st_stm32/common”:
○ introduced to factorize cross-series code (MPU
code for now)
● MCU specific code:
○ further optimized with device tree
arch/arm/soc/st_stm32
○ common (new! More code to be put here)
○ stm32f1
■ Kconfig.defconfig.stm32f103xx
■ Kconfig.defconfig.stm32f107xc
■ …
○ ….
○ stm32l4
ENGINEERS
AND DEVICES
WORKING
TOGETHER
Device tree concept applied to
STM32 family
ENGINEERS AND DEVICES
WORKING TOGETHER
STM32 device tree: Zephyr vs Linux (1/2)
● STM32 dts files deployed in Zephyr and Linux in parallel
● Long term goal: Common repo
● No dependency today
● Respective evolutions monitored and controlled
○ Divergence points are listed
○ Regular alignments done
○ Linux kernel STM32 machine maintainer is reviewer of STM32 Zephyr dts PRs
● Today, alignments are only done in one way:
○ Linux => Zephyr
● Once device tree will be stabilized in Zephyr:
○ Linux <=> Zephyr
ENGINEERS AND DEVICES
WORKING TOGETHER
STM32 device tree: Zephyr vs Linux (2/2)
● Known Issues (and current solutions):
○ Properties:
■ Different drivers > Different properties
■ Current solution: Use of string prefix “zephyr,” (Eg: “zephyr,bt-uart”)
○ Bindings:
■ Different drivers > Different bindings
■ Current solution: Use same paths/same file names but different #define
○ Supported set of SoCs: More MCUs in Zephyr (in which Linux won’t fit)
■ => MCU with smallest configuration is different
■ Current answer is to use generic stm32XX.dtsi files to store this minimum configuration
ENGINEERS AND DEVICES
WORKING TOGETHER
STM32 device tree organization
stm32f4.dtsi
soc{ rcc
pinctrl
uart1
uart2
…
i2c1
i2c2}
stm32f4-pinctrl.dtsi
soc {pinctrl { usart1_pin_a{ tx =, rx=}
usart2_pin_a{ …}
…
i2c1_pin_a
i2c2_pin_b}}
armv7-m.dtsi
stm32f401.dtsi
stm32f407.dtsi
soc{ usart3
uart4
uart5}
stm32f407-pinctrl.dtsi
soc{ pinctrl{ usart3_pin_a
uart4_pin_a
uart5_pin_a}}
…
ENGINEERS
AND DEVICES
WORKING
TOGETHER
What’s next for STM32 in Zephyr
●Keep extending STM32 drivers support
●Complete STM32 code factorization (still some duplicated
code between series)
●Expand connectivity support for disco IoT board
○Wi-Fi support
○Sub-GHZ
○NFC…
○USB
ENGINEERS
AND DEVICES
WORKING
TOGETHER
Back up sildes
ENGINEERS AND DEVICES
WORKING TOGETHER
STM32 prototyping boards and shields
ENGINEERS AND DEVICES
WORKING TOGETHER
Status on STM32 presence in Zephyr (17’09)
• 4 series present (F1, F3, F4, L4)
• 21 SoCs ported
• 22 Boards available
GPIO/
Pinmux
RCC UART I2C SPI RNG PWM Flash DMA EXTI ETH
stm32f1
4 socs
4 boards
Z LL HAL/LL LL LL LL HAL NA NA Z NA
stm32f3
3 socs
3 boards
Z LL HAL/LL LL LL LL HAL Z NA Z NA
stm32f4
10 socs
11 boards
Z LL HAL/LL LL LL LL HAL Z Z Z HAL
stm32l4
4 socs
4 boards
Z LL HAL/LL LL LL LL HAL Z NA Z NA
Available
Issues reported
Z: Zephyr native
LL: Based on STM32CUBE LL
HAL: Based on STM32CUBE HAL
Legend:
ENGINEERS
AND DEVICES
WORKING
TOGETHER
Zephyr STM32 Misc
• BT available with X-Nucleo shield or embedded on Disco
IoT Board
• Activate with CONFIG_BT_SPI_BLUENRG
Thank You
Contact: erwan.gouriou@linaro.org
#SFO17
SFO17 keynotes and videos on: connect.linaro.org
For further information: www.linaro.org

Deploy STM32 family on Zephyr - SFO17-102

  • 1.
    Deploy STM32 familyon Zephyr Erwan Gouriou
  • 2.
    ENGINEERS AND DEVICES WORKING TOGETHER Plan ● Aglance at STM32 ecosystem ● STM32 porting on Zephyr ● Device tree concept applied to STM32 family ● What’s next for STM32 in Zephyr
  • 3.
  • 4.
    ENGINEERS AND DEVICES WORKINGTOGETHER Quick outlook on STM32 SoC family ● Cortex-M based MCUs ● More than 700 SoC part numbers ● Split in 10 series ● STM32 family keeps evolving and more to come… ● http://www.st.com/en/microcontrollers /stm32-32-bit-arm-cortex-mcus.html ● «MCU finder» utility: ●http://www.st.com/en/development-tool s/st-mcu-finder.html
  • 5.
    ENGINEERS AND DEVICES WORKINGTOGETHER STM32 MCU naming convention STM32 F 0 3 Family STM32 Cortex 32bit Lines : 0 Value 1 Access 2 USB 3 --- 4 --- 5 OTG 6 LCD/TFT+OTG 7 Ethernet 8 Regulator off 9 LCD TFT Sub-Lines: 0 --- 1 --- 2 --- 3 --- Small die 4 --- 5 --- Medium die 6 --- 7 --- Big die 8 --- 9 --- High integration Product type F Foundation L Ultra-low-power H High performance A higher number means a richer configuration! 1 R Flash size (Kbytes) : 4 16 6 32 8 64 B 128 C 256 D 384 E 512 F 768 G 1024 H 1536 I 2048 B Package: F 20 pins G 28 pins K 32 pins T 36 pins S 44 pins C 48 pins R 64, 66 pins M 80 pins O 90 pins Series Number: 0 Cortex-M0 1 Cortex-M3 2 Cortex-M3 3 Cortex-M4 4 Cortex-M4 7 Cortex-M7
  • 6.
    ENGINEERS AND DEVICES WORKINGTOGETHER Focus on B-L475E-IOT01A (disco_l475_iot1) STM32L475 SoC: Low power, 80MHz 1Mbit flash 128 kRAM Inventek ISM43362-M3G: Wi-Fi Module M24SR: NFC Module VLX53L0X: Time of Flight and gesture recognition HTS221: Humidity and Temperature USB OTG Arduino V3 connector SPSGRF:Sub-GHz Module 64MBit Quad-SPI Flash MP34DT01: Omnidirectionnal mic (x2) SPBTLE-RF: BT Module LIS3MDL: 3-Axis magnetometer LPS22HB: Barometer LMS6DSL: 3D accelerometer and gyroscope Connectivity Sensing MCU Status: Upstreamed In progress
  • 7.
    ENGINEERS AND DEVICES WORKINGTOGETHER STM32Cube: Embedded Software for STM32 http://www.st.com/en/embedded-software/stm32cube-embedded-software.html
  • 8.
    ENGINEERS AND DEVICES WORKINGTOGETHER STM32Cube APIs: HAL vs LL ● HAL (Hardware Abstraction Layers): ○ High level and functional abstraction ○ 100% coverage of all peripherals ○ Good match for complex drivers such as USB, Ethernet, .. ○ Higher portability => bigger software footprints, more time running adaptation code => Less optimized ● LL (Low-Layers): ○ Light-weight, optimized, expert oriented set of APIs designed for both performance and runtime efficiency ○ Register level access library. Do not use global variables. Atomic operations ○ Fit for most zephyr drivers and allows to build stm32 generic lightweight drivers. ○ Perfect fit for “simple IPs” drivers ● HAL/LL could be used together in a single driver
  • 9.
    ENGINEERS AND DEVICES WORKINGTOGETHER Main STM32Cube benefit: Abstraction ● Usual prejudices on HAL: ○ Size, sub optimization ○ coding style… ● Usual pro-HAL arguments are: ○ Avoid re-inventing the wheel, allow to save time… ○ Thoroughly maintained and validated, help developing more mature drivers ● Abstraction capability breaks silos between series/re-inforces cooperation ○ Focussed competencies: more users and more reviewers on a single driver ○ More minds: more performant drivers ○ Reduce work duplication: faster increase of driver support ○ Less code: maintenance effort is reduced.
  • 10.
  • 11.
    ENGINEERS AND DEVICES WORKINGTOGETHER STM32Cube: Integration in Zephyr ext/hal/st/stm32cubearch/arm/soc/st_stm32/ ○ stm32f1xx/ ○ stm32f3xx/ ■ drivers/ (HAL and LL) ● include/ ● src/ ■ soc / (CMSIS Files: stm32f303x8.h) ■ README ○ stm32f4xx ○ … ● Maintained and updated at each Zephyr DV (at least) ● STM32Cube, as an external library, should not be modified ● But: in case of genuine STM32Cube bug: ○ Report to STM32Cube Zephyr maintainer (issue will be raised in ST bugtracker) ○ Fix issue in a separate PR. Document README (ST Bug ref / Impacted files) ○ Reported issues are taken into account / Don’t hesitate to report issues!
  • 12.
    ENGINEERS AND DEVICES WORKINGTOGETHER How to: Introduce a new LL/HAL based driver ● HAL or LL? ○ Driver complexity? ○ Acceptable footprint? ○ Supported features? ○ Validation effort? ● Maximize code reuse ○ Use CMSIS defines ● Adapt code structure to IP diversity ○ Factorise as much as possible. Examples => Small variations within family: spi_ll_stm32.c (use of #ifdef’s) 2 different IPs in whole family (v1/v2): i2c_ll_stm32.c i2c_ll_stm32_v1.c (I2C V1: F1/F2/F4/L1) i2c_ll_stm32_v2.c (I2C V2: F0/F3/F7/L4) Important heterogeneity: stm32_ll_clock.c stm32f1x_ll_clock.c (F1 series) stm32f3x_ll_clock.c (F3 series) … ● Lot of HAL/LL examples in stm32cube packages ● Community support on https://community.st.com
  • 13.
    ENGINEERS AND DEVICES WORKINGTOGETHER STM32 MCU porting: Minimize code duplication ● Code organized per series ● In each series: ○ MCUspecific info (number of IRQ, SoC refence) is stored under Kconfig.defconfig.stm32yyyxx ○ Series Kconfig are defined ● New: “st_stm32/common”: ○ introduced to factorize cross-series code (MPU code for now) ● MCU specific code: ○ further optimized with device tree arch/arm/soc/st_stm32 ○ common (new! More code to be put here) ○ stm32f1 ■ Kconfig.defconfig.stm32f103xx ■ Kconfig.defconfig.stm32f107xc ■ … ○ …. ○ stm32l4
  • 14.
  • 15.
    ENGINEERS AND DEVICES WORKINGTOGETHER STM32 device tree: Zephyr vs Linux (1/2) ● STM32 dts files deployed in Zephyr and Linux in parallel ● Long term goal: Common repo ● No dependency today ● Respective evolutions monitored and controlled ○ Divergence points are listed ○ Regular alignments done ○ Linux kernel STM32 machine maintainer is reviewer of STM32 Zephyr dts PRs ● Today, alignments are only done in one way: ○ Linux => Zephyr ● Once device tree will be stabilized in Zephyr: ○ Linux <=> Zephyr
  • 16.
    ENGINEERS AND DEVICES WORKINGTOGETHER STM32 device tree: Zephyr vs Linux (2/2) ● Known Issues (and current solutions): ○ Properties: ■ Different drivers > Different properties ■ Current solution: Use of string prefix “zephyr,” (Eg: “zephyr,bt-uart”) ○ Bindings: ■ Different drivers > Different bindings ■ Current solution: Use same paths/same file names but different #define ○ Supported set of SoCs: More MCUs in Zephyr (in which Linux won’t fit) ■ => MCU with smallest configuration is different ■ Current answer is to use generic stm32XX.dtsi files to store this minimum configuration
  • 17.
    ENGINEERS AND DEVICES WORKINGTOGETHER STM32 device tree organization stm32f4.dtsi soc{ rcc pinctrl uart1 uart2 … i2c1 i2c2} stm32f4-pinctrl.dtsi soc {pinctrl { usart1_pin_a{ tx =, rx=} usart2_pin_a{ …} … i2c1_pin_a i2c2_pin_b}} armv7-m.dtsi stm32f401.dtsi stm32f407.dtsi soc{ usart3 uart4 uart5} stm32f407-pinctrl.dtsi soc{ pinctrl{ usart3_pin_a uart4_pin_a uart5_pin_a}} …
  • 18.
    ENGINEERS AND DEVICES WORKING TOGETHER What’s nextfor STM32 in Zephyr ●Keep extending STM32 drivers support ●Complete STM32 code factorization (still some duplicated code between series) ●Expand connectivity support for disco IoT board ○Wi-Fi support ○Sub-GHZ ○NFC… ○USB
  • 19.
  • 20.
    ENGINEERS AND DEVICES WORKINGTOGETHER STM32 prototyping boards and shields
  • 21.
    ENGINEERS AND DEVICES WORKINGTOGETHER Status on STM32 presence in Zephyr (17’09) • 4 series present (F1, F3, F4, L4) • 21 SoCs ported • 22 Boards available GPIO/ Pinmux RCC UART I2C SPI RNG PWM Flash DMA EXTI ETH stm32f1 4 socs 4 boards Z LL HAL/LL LL LL LL HAL NA NA Z NA stm32f3 3 socs 3 boards Z LL HAL/LL LL LL LL HAL Z NA Z NA stm32f4 10 socs 11 boards Z LL HAL/LL LL LL LL HAL Z Z Z HAL stm32l4 4 socs 4 boards Z LL HAL/LL LL LL LL HAL Z NA Z NA Available Issues reported Z: Zephyr native LL: Based on STM32CUBE LL HAL: Based on STM32CUBE HAL Legend:
  • 22.
    ENGINEERS AND DEVICES WORKING TOGETHER Zephyr STM32Misc • BT available with X-Nucleo shield or embedded on Disco IoT Board • Activate with CONFIG_BT_SPI_BLUENRG
  • 23.
    Thank You Contact: erwan.gouriou@linaro.org #SFO17 SFO17keynotes and videos on: connect.linaro.org For further information: www.linaro.org