Getting Started With Stm32Cubewl For Stm32Wl Series: User Manual
Getting Started With Stm32Cubewl For Stm32Wl Series: User Manual
User manual
Introduction
STM32Cube is an STMicroelectronics original initiative to significantly improve developer productivity by reducing development
effort, time and cost. STM32Cube covers the whole STM32 portfolio.
STM32Cube includes:
• A set of user-friendly software development tools to cover project development from the design to the production, among
which:
– STM32CubeMX, a graphical software configuration tool that allows the automatic generation of C initialization code
using graphical wizards.
– STM32CubeProgrammer (STM32CubeProg), a programming tool available with both graphical and command-line
interfaces.
– STM32CubeMonitor-Power (STM32CubeMonPwr), a monitoring tool to measure and to help optimizing the MCU
power consumption.
– STM32CubeMonitor-RF, a versatile monitoring tool with a dedicated add-on to perform RF tests with STM32WL
(dynamic packet transmission/reception, PER measurements) with a graphical representation of RF performance over
time.
• A comprehensive embedded software platform, delivered per series (such as STM32CubeWL for STM32WL Series):
– The STM32Cube HAL, STM32 abstraction layer embedded software ensuring maximized portability across STM32
portfolio.
– Low-layer APIs (LL) offering a fast light-weight expert-oriented layer which is closer to the hardware than the HAL.
LL APIs are available only for a set of peripherals.
– A consistent set of middleware components such as FatFS, FreeRTOS™, LoRaWAN®, SubGHz_Phy, Sigfox™, KMS,
SE and mbedCrypto.
– All embedded software utilities coming with a full set of examples.
The STM32CubeWL MCU Package runs on STM32 32-bit microcontrollers based on the Arm® Cortex®-M
processor.
Note: Arm is a registered trademark of Arm Limited (or its subsidiaries) in the US and/or elsewhere.
STM32CubeWL gathers, in a single package, all the generic embedded software components required to develop
an application on STM32WL microcontrollers. In line with the STM32Cube initiative, this set of components is
highly portable, not only within STM32WL Series but also to other STM32 Series.
STM32CubeWL is fully compatible with STM32CubeMX code generator that allows generating initialization code.
The package includes low-layer (LL) and hardware abstraction layer (HAL) APIs that cover the microcontroller
hardware, together with an extensive set of examples running on STMicroelectronics boards. The HAL and LL
APIs are available in open-source BSD license for user convenience.
STM32CubeWL MCU Package also contains a set of middleware components with the corresponding examples.
They come in free user-friendly license terms:
• CMSIS-RTOS implementation with FreeRTOS™ open source solution
• FAT file system based on open source FatFS solution
SubGHZ_Phy mbedCrypto
(1)
Middleware level Utilities
Board support package (BSP) Low-layer APIs (LL) Hardware abstraction layer APIs (HAL)
The STM32CubeWL firmware solution is built around three independent levels that easily interact as described in
Figure 2.
Applications
Level 1
Library and protocol based components
(for example FatFS, FreeRTOS™ or LoRaWAN®)
Examples
HAL
2.1 Level 0
This level is divided into three sub-layers:
• Board support package (BSP)
• Hardware abstraction layer (HAL)
– HAL peripheral drivers
– Low-layer drivers
• Basic peripheral usage examples
The BSP is based on a modular architecture allowing an easy porting on any hardware by just implementing the
low-level routines.
• Each target configuration has its own option settings: target device, linker options, RO, RW zones,
preprocessor symbols (CORE_CM0PLUS) so that user code can be compiled, linked and programmed
separately for each core. The compilation results in two binaries: CM4 binary and CM0+ binary.
2.2 Level 1
This level is divided into two sub-layers:
• Middleware components
• Examples based on the middleware components
• LoRaWAN®
– It offers a very compelling mix of long range, low power consumption and secure data transmission.
Public and private networks using this technology can provide coverage that is greater in range
compared to that of existing cellular networks. It is easy to plug into the existing infrastructure and
offers a solution to serve battery-operated IoT applications.
• SubGHz_Phy
– It implements the PHY layer for sub-gigahertz protocol. Although specialized for LoRaWAN® MAC it
can interface most sub-gigahertz protocol. It provides an abstraction layer managing transmission,
radio reception handlers and timeouts. With its unique radio API, it also implements several radio
drivers for other I-CUBE-LRAWAN
• Sigfox™
– It implements the Sigfox™ protocol library compliant with the Sigfox™ protocol Network. It is also
including the RF test protocol library to test against RF Sigfox™ tools.
• SE
– The secure engine middleware (SE) provides a protected environment to manage all critical data and
operations (such as cryptography operations accessing firmware encryption key and others). Protected
code and data are accessible through a single entry point (called gate mechanism) and it is therefore
not possible to run or access any SE code or data without passing through it, otherwise, a system reset
is generated.
• KMS
– The key management services middleware (KMS) provides cryptographic services to the user
application through the PKCS #11 APIs (KEY ID-based APIs). Security is insured by locating KMS in
the secure enclave. User application keys are stored in the secure enclave and can be updated in a
secure way (authenticity check, decryption, and integrity check before the update).
• mbedCrypto
– mbedCrypto middleware is delivered as open source code. This middleware provides a PSA
cryptography API implementation.
STM32CubeWL features a rich set of examples and applications at all levels making it easy to understand and
use any HAL driver and/or middleware components. These examples run on the STMicroelectronics boards listed
in Table 1.
Supported boards
NUCLEO-WL55JC
Sub-GHz Middlewares
(Phy Layer and MAC
layers)
Attention: The components files must not be modified by the user. Only the \Projects sources are eligible to changes by
the user.
For NUCLEO-WL55JC board, a set of examples are provided with pre-configured projects for EWARM toolchain.
Figure 5 shows the project structure for the NUCLEO-WL55JC board.
The examples are classified depending on the STM32Cube level they apply to, and are named as explained
below:
• Level 0 examples are called Examples, Examples_LL and Examples_MIX. They use respectively HAL
drivers, LL drivers and a mix of HAL and LL drivers without any middleware component.
• Level 1 examples are called Applications. They provide typical use cases of each middleware component.
The LoRaWAN folder contains typical Lora use cases.
Templates projects available in the Templates and Templates_LL directories permit to quickly build any firmware
application on a given board. Two projects are available in each template directory: single core for all STM32WL
lines and dual core projects for STM32WL5x (dual core) line.
Single core examples have the same structure:
• \Inc folder that contains all header files.
• \Src folder for the sources code.
• \EWARM, \MDK-ARM, \STM32CubeIDE folders contain the pre-configured project for each toolchain.
• readme.txt describing the example behavior and needed environment to make it working
• *.ioc file that allows users to open most of firmware examples within STM32CubeMX (starting from
STM32CubeMX 6.1.0)
All dual core examples have the same structure:
• Two separate folders CM4 and CM0PLUS respectively for Cortex®‑M4 and Cortex®‑M0+
• Each folder (CM4 and CM0PLUS) provides:
– \Inc folder that contains all header files for Cortex®‑M4/M0+
– \Src folder for the sources code files for Cortex®‑M4/M0+
• A \common folder with \Inc and \Src containing the common header and source files for both cores.
• \EWARM, \MDK-ARM, \STM32CubeIDE folders contain the pre-configured project for each toolchain (both
Cortex®‑M4 and Cortex®‑M0+ target configuration)
• readme.txt describing the example behavior and needed environment to make it working
• *.ioc file that allows users to open most of firmware examples within STM32CubeMX (starting from
STM32CubeMX 6.1.0)
• The initialization source code of such projects is generated by STM32CubeMX; the main application source
code is contained by the comments “USER CODE BEGIN” and “USER CODE END”. In case the IP
selection and setting are modified, STM32CubeMX updates the initialization part of the code but preserves
the main application source code.
For developing a custom project in the STM32CubeMX, follow the step-by-step process:
1. Select the STM32 microcontroller that matches the required set of peripherals.
2. Configure all the required embedded software using a pinout-conflict solver, a clock-tree setting helper, a
power consumption calculator, and the utility performing MCU peripheral configuration (such as GPIO or
USART) and middleware stacks (such as USB).
3. Generate the initialization C code based on the selected configuration. This code is ready to use within
several development environments. The user code is kept at the next code generation.
For more information about STM32CubeMX, refer to the STM32CubeMX for STM32 configuration and
initialization C code generation (UM1718).
For a list of the available example projects for the STM32CubeWL, refer to the STM32Cube firmware examples
for STM32WL Series application note (AN5409).
4.2.2.2 LL application
This section describes the steps needed to create your own LL application using STM32CubeWL.
1. Create your project
To create a new project you either start from the Templates_LL project provided for each board under
\Projects\<STM32xxx_yyy>\Templates_LL or from any available project under \Projects\<STM32xxy_yyy>
\Examples_LL (<STM32xxx_yyy> refers to the board name, such as NUCLEO-WL55JC).
The Template project provides an empty main loop function, however it is a good starting point to get familiar
with project settings for STM32CubeWL.
Template main characteristics are the following:
– It contains the source codes of the LL and CMSIS drivers which are the minimal components needed
to develop code on a given board.
– It contains the include paths for all the required firmware components.
– It selects the supported STM32WL device and allows to configure the CMSIS and LL drivers
accordingly.
– It provides ready-to-use user files, that are pre-configured as follows:
main.h: LED & USER_BUTTON definition abstraction layer.
main.c: System clock configuration for maximum frequency.
2. Port an existing project to another board
To port an existing project to another target board, start from the Templates_LL project provided for each
board and available under \Projects\<STM32xxx_yyy>\Templates_LL:
a. Select a LL example
To find the board on which LL examples are deployed, refer to the list of LL examples
STM32CubeProjectsList.html.
b. Port the LL example
◦ Copy/paste the Templates_LL folder - to keep the initial source - or directly update existing
Templates_LL project.
◦ Then porting consists principally in replacing Templates_LL files by the Examples_LL targeted
project.
◦ Keep all board specific parts. For reasons of clarity, board specific parts have been flagged with
specific tags:
1. Start from a dual core project. To ease project creation, some minimalist dual core projects are available in
STM32WL firmware package:
– Template dual core using HAL driver:
...\Firmware\Projects\NUCLEO-WL55JC\Templates\DualCore
– Template dual core using LL driver:
...\Firmware\Projects\NUCLEO-WL55JC\Templates_LL\DualCore
2. Select any example single core to migrate to CPU2
3. Copy source files from example to template.
Example with HAL example GPIO_EXTI migration to dual core template:
– Copy content of GPIO_EXTI/Inc to Templates\DualCore\CM0PLUS\Inc
– Copy content of GPIO_EXTI/Src to Templates\DualCore\CM0PLUS\Src
Note: Program of CPU1 is compatible with CPU2, therefore can be executed by CPU2, with some exceptions:
◦ IRQ handlers and interruptions are specific to selected core: In files stm32wlxx_it.h and stm32wlxx_it.c,
IRQ handlers must be customized to the selected core. In source files, interruptions configurations with
NVIC functions must also be customized accordingly. For example, IRQ handler MemManage_Handler is
available only on CPU1 (CM4). Refer to list of IRQ handlers in startup files of the selected CPU.
◦ Few peripherals features are specific to selected core: refer to compilation switch CORE_CM0PLUS in HAL
and LL drivers.
4. Remove system clock configuration in CPU1 program: dual core templates perform system clock
configuration by CPU1 (generic configuration) before performing CPU2 boot. By copying example program
in CPU2 folder, system clock configuration is also performed by CPU2. This system clock configuration is
matching the example requirements and must be kept.
Note: An alternate solution is to perform system clock configuration by CPU1 only, with configuration matching the
example requirements. However, in case of wake up from Standby or Shutdown modes, CPU2 program must
have the routines to restore system clock.
Note: Program of CPU1 is now performing only 1 action: boot CPU2.
5. Optionally, CPU1 can be put in low power mode after CPU2 boot. The deepest low power mode is
recommended (Shutdown mode) to allow CPU2 to manage all system low power modes (Stop, Standby,
Shutdown) on demand.
Example of code to make CPU1 enter in Shutdown mode using HAL driver:
Caution: Regeneration of dual core template with CubeMX (file .ioc) would overwrite the code migrated previously
Optionally, CubeMX configuration of the dual core template (file .ioc) can be updated to match the example
migrated to CPU2.
4.2.4 RF applications
Three types of RF application are available in the package. They are listed below:
LoRaWan® examples are LoRaWan® examples implementing a LoRaWan® device exercising the LoRaWan®
stack and the SubGHz_Phy RF driver. They are located in Projects\NUCLEO-WL55JC\Applications\LoRaWAN.
• LoRaWAN_AT_Slave implements a LoRaWan® modem that is controlled though AT command interface over
UART by an external host. This application is available in single core and dual core format with and without
KMS (key management system). More information can be found in AN5406 and AN5481.
LoRaWAN_AT_Slave devices can be connected to STM32CubeMonitor to send AT commands to the
device, perform packet error rate measurement and more.
• LoRaWAN_End_Node implements a LoRaWan® application device sending sensors data to LoRaWan®
network server. This application is available in single core, dual core with optionally FreeRTos and KMS.
More information can be found in in AN5406.
• LoRaWAN_FUOTA implements a dual core LoRaWan® application device sending sensors data to
LoRaWan® network server. Moreover, the LoRaWan® application and stack can be updated over the air
from a LoRaWan® network server using the SBSFU as a secure boot and secure firmware update
framework. As well, the LoRaWAN_FUOTA example is fully secured using isolation features provided by the
STM32WL55. More information is provided under AN5554.
SubGHz_Phy example: these applications features the PingPong application available in both single core and
dual core format. The PingPong application features a radio link between two PingPong devices. These examples
can be found under Projects\NUCLEO-WL55JC\Applications\SubGHz_Phy. More information is provided under
AN5406.
Sigfox™ example: these applications implement Sigfox™ up and running Sigfox™ device. They can be found in
project path Projects\NUCLEO-WL55JC\Applications\Sigfox
• Sigfox™ applications are available in both single core and dual core format. Dual core project can run with
or without KMS. More information is provided under AN5480.
• Sigfox_AT_Slave implements a Sigfox™ application modem that is controlled though AT command interface
over UART by an external host, like a computer executing a terminal.
• Sigfox_PushButton an example of a Sigfox™ object sending temperature and battery level to a Sigfox™
network when pressing a user button.
4.2.5 RF demonstration
The local network demonstration features a non LoRaWan® local network with one concentrator and up to 14
sensors that can connect and send sensor data to the concentrator. More information is provided in UM2786.
Local network projects are located under Projects\NUCLEO-WL55JC\Demonstrations\LocalNetwork.
• One concentrator project flashed into STM32WLxx_Nucleo board implements a concentrator sending one
beacon frame and one sync frame every 16 seconds to administrate a network of up to 14 sensors and
receives each connected sensor data. The concentrator can be connected to STM32CubeMonitor to
configure the geographical area and display the list of sensors detected and connected sensor data.
• One sensor project that implements one sensor sending data to the concentrator.
5 FAQ
5.3 Are any examples provided with the ready-to-use toolset projects?
Yes. STM32CubeWL provides a rich set of examples and applications. They come with the pre-configured
projects for IAR™-based toolchain.
5.5 Does the HAL layer take benefit from interrupts or DMA? How can this be
controlled?
Yes. The HAL layer supports three API programming models: polling, interrupt and DMA (with or without interrupt
generation).
5.9 Can I use HAL and LL drivers together? If yes, what are the constraints?
It is possible to use both HAL and LL drivers. One handles the peripheral initialization phase with HAL and then
manages the I/O operations with LL drivers.
The major difference between HAL and LL is that HAL drivers require to create and use handles for operation
management while LL drivers operate directly on peripheral registers. Mixing HAL and LL is illustrated in
Examples_MIX example.
5.10 Are there any LL APIs which are not available with HAL?
Yes, there are.
A few Cortex® APIs have been added in stm32wlxx_ll_cortex.h , for instance for accessing SCB or SysTick
registers.
5.14 How to get regular updates on the latest STM32CubeWL MCU Package
releases?
Refer to Section 4.2.6 .
Revision history
Contents
1 STM32CubeWL main features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
2 STM32CubeWL architecture overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
2.1 Level 0 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
2.1.1 Board support package (BSP). . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
2.2 Level 1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
2.2.1 Middleware components . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
4.2.4 RF applications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
4.2.5 RF demonstration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
5 FAQ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .18
5.1 What is the license scheme for the STM32CubeWL firmware? . . . . . . . . . . . . . . . . . . . . . . . 18
5.2 What boards are supported by the STM32CubeWL firmware package? . . . . . . . . . . . . . . . . 18
5.3 Are any examples provided with the ready-to-use toolset projects?. . . . . . . . . . . . . . . . . . . . 18
5.4 Is there any link with standard peripheral libraries? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
5.5 Does the HAL layer take benefit from interrupts or DMA? How can this be controlled? . . . 18
5.6 How are the product/peripheral specific features managed?. . . . . . . . . . . . . . . . . . . . . . . . . . 18
5.7 When should I use HAL versus LL drivers? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
5.8 How can I include LL drivers in my environment? Is there any LL configuration file as for
HAL?. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
5.9 Can I use HAL and LL drivers together? If yes, what are the constraints? . . . . . . . . . . . . . . 19
5.10 Are there any LL APIs which are not available with HAL? . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
5.11 Why are SysTick interrupts not enabled on LL drivers? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
5.12 How are LL initialization APIs enabled? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
5.13 How can STM32CubeMX generate code based on embedded software? . . . . . . . . . . . . . . 19
5.14 How to get regular updates on the latest STM32CubeWL MCU Package releases? . . . . . . 19
List of tables
Table 1. Macros for STM32WL Series. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
Table 2. Boards for STM32WL Series . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
Table 3. Document revision history . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
List of figures
Figure 1. STM32CubeWL firmware components. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
Figure 2. STM32CubeWL firmware architecture . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
Figure 3. Dual core project architecture . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
Figure 4. STM32CubeWL firmware package structure. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
Figure 5. Overview of STM32CubeWL examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9