Um1718 Stm32cubemx For Stm32 Configuration and Initialization C Code Generation Stmicroelectronics
Um1718 Stm32cubemx For Stm32 Configuration and Initialization C Code Generation Stmicroelectronics
User manual
STM32CubeMX for STM32 configuration
and initialization C code generation
Introduction
STM32CubeMX is a graphical tool for STM32 products. It is part of the STM32Cube initiative
(see Section 1), and is available as a standalone application as well as in the
STM32CubeIDE toolchain.
STM32CubeMX has the following key features:
• Easy microcontroller selection covering the whole STM32 portfolio
• Board selection from a list of STMicroelectronics boards
• Easy microcontroller configuration (pins, clock tree, peripherals, middleware) and
generation of the corresponding initialization C code
• Easy switching to another microcontroller by importing a previously-saved
configuration to a new MCU project
• Easy exporting of current configuration to a compatible MCU
• Generation of configuration reports
• Generation of embedded C projects for a selection of integrated development
environment tool chains (STM32CubeMX projects include the generated initialization C
code, MISRA 2004 compliant STM32 HAL drivers, the middleware stacks required for the
user configuration, and all the relevant files for opening and building the project in the
selected IDE)
• Power consumption calculation for a user-defined application sequence
• Self-updates allowing the user to keep STM32CubeMX up-to-date
• Download and update of STM32Cube embedded software required for user application
development (see Appendix E for details on the STM32Cube embedded software offer)
• Download of CAD resources (schematic symbols, PCB footprints, and 3D models)
Although STM32CubeMX offers a user interface and generates C code compliant with
STM32 MCU design and firmware solutions, users need to refer to the product technical
documentation for details on actual implementation of peripherals and firmware. The
following documents are available on www.st.com:
• STM32 microcontroller reference manuals and datasheets
• STM32Cube HAL/LL driver user manuals for STM32C0 (UM2985), STM32F0
(UM1785), STM32F1 (UM1850), STM32F2 (UM1940), STM32F3 (UM1786), STM32F4
(UM1725), STM32F7 (UM1905), STM32G0 (UM2303), STM32G4 (UM2570), STM32H5
(UM3132), STM32H7 (UM2217), STM32L0 (UM1749), STM32L1 (UM1816),
STM32L4/L4+ (UM1884), STM32L5 (UM2659), STM32MP1
(https://wiki.st.com/stm32mpu), STM32U5 (UM2883), STM32WL (UM2642), STM32WB
(UM2442), and STM32WBA (UM3131).
Contents
1 STM32Cube overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
18.3.8 Queue description: configuring the DMA channel hosting the queue . 375
18.3.9 Node description: accessing contextual help and documentation . . . . 376
18.3.10 Node description: configuring node parameters . . . . . . . . . . . . . . . . . 377
18.3.11 Node description: configuring a trigger . . . . . . . . . . . . . . . . . . . . . . . . 378
18.3.12 Node description: reconfiguring a DMA for Data transfer . . . . . . . . . . 379
18.4 Checking the LPBAM design . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 381
18.5 Generating a project with LPBAM applications . . . . . . . . . . . . . . . . . . . 382
18.6 LPBAM application for TrustZone activated projects . . . . . . . . . . . . . . . 383
19 FAQ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 387
19.1 I encountered a network connection error during a download
from STM32CubeMX. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 387
19.2 Since I changed my login to access the Internet, some
software packs appear not available. . . . . . . . . . . . . . . . . . . . . . . . . . . . 387
19.3 On dual-context products, why some peripherals or
middleware are not available for a given context? . . . . . . . . . . . . . . . . . 387
19.4 On the Pinout configuration panel, why does STM32CubeMX
move some functions when I add a new peripheral mode? . . . . . . . . . . 387
19.5 How can I manually force a function remapping? . . . . . . . . . . . . . . . . . 387
19.6 Why some pins are highlighted in yellow or in light green in
the Pinout view? Why I cannot change the function of some
pins (when I click some pins, nothing happens)? . . . . . . . . . . . . . . . . . . 388
19.7 Why does the RTC multiplexer remain inactive on the Clock tree view? 388
19.8 How can I select LSE and HSE as clock source and
change the frequency? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 388
19.9 Why STM32CubeMX does not allow me to configure
PC13, PC14, PC15, and PI8 as outputs when one of them
is already configured as an output? . . . . . . . . . . . . . . . . . . . . . . . . . . . . 389
19.10 Ethernet configuration: why cannot I specify DP83848
or LAN8742A in some cases? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 389
19.11 How to fix MX_DMA_Init call rank in STM32CubeMX
generated projects? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 389
19.12 When is the PeriphCommonClock_Config() function
generated? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 390
19.13 How to handle thread-safe solution in STM32CubeMX and
STM32CubeIDE? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 390
List of tables
List of figures
Figure 99. Clock tree configuration: enabling RTC, RCC clock source
and outputs from Pinout view . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 132
Figure 100. Clock tree configuration: RCC peripheral advanced parameters . . . . . . . . . . . . . . . . . . . 133
Figure 101. Project Settings window . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 135
Figure 102. Project folder. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 136
Figure 103. Selecting a basic application structure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 138
Figure 104. Selecting an advanced application structure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 139
Figure 105. OpenSTLinux settings (STM32MP1 series only) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 139
Figure 106. Selecting a different firmware location . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 140
Figure 107. Firmware location selection error message . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 140
Figure 108. Recommended new firmware repository structure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 140
Figure 109. Project Settings code generator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 142
Figure 110. Template Settings window . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 143
Figure 111. Generated project template . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 144
Figure 112. Advanced Settings window . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 145
Figure 113. Generated init functions without C language “static” keyword . . . . . . . . . . . . . . . . . . . . . 146
Figure 114. Automatic project import . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 147
Figure 115. Manual project import . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 148
Figure 116. Import Project menu - Try Import with errors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 149
Figure 117. Import Project menu - Successful import after adjustments . . . . . . . . . . . . . . . . . . . . . . . 150
Figure 118. Set unused pins window . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 151
Figure 119. Reset used pins window . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 151
Figure 120. Set unused GPIO pins with Keep Current Signals Placement checked . . . . . . . . . . . . . . 152
Figure 121. Set unused GPIO pins with Keep Current Signals Placement unchecked . . . . . . . . . . . . 153
Figure 122. Additional Software window . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 155
Figure 123. Component dependency resolution . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 158
Figure 124. Details and Warnings panel . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 160
Figure 125. Selection of additional software components . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 161
Figure 126. Additional software components - Updated tree view. . . . . . . . . . . . . . . . . . . . . . . . . . . . 161
Figure 127. LPBAM window. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 162
Figure 128. CAD Resources view . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 163
Figure 129. CAD Resources not available . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 164
Figure 130. CAD Resources selection for download . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 164
Figure 131. CAD Resources in Tools panel. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 165
Figure 132. CAD Resources for STM32CubeMX project. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 165
Figure 133. Boot path configuration ecosystem. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 166
Figure 134. Boot paths for STM32H57x devices . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 167
Figure 135. Boot paths for STM32H56x devices . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 167
Figure 136. Application boot paths (legacy and ST-iRoT projects) . . . . . . . . . . . . . . . . . . . . . . . . . . . 167
Figure 137. Application boot paths (OEM-iRoT and Secure manager projects) . . . . . . . . . . . . . . . . . 168
Figure 138. Application boot path (ST-iRoT and OEM-uRoT assembled) . . . . . . . . . . . . . . . . . . . . . . 168
Figure 139. Application boot path:
(ST-iRoT and OEM-uRoT Secure/Non-Secure project) . . . . . . . . . . . . . . . . . . . . . . . . . . 169
Figure 140. Application boot path:
(ST-iRoT and Secure/Non-Secure user application assembled) . . . . . . . . . . . . . . . . . . . 169
Figure 141. Application boot path:
(ST-iRoT and OEM-uRoT Secure/Non-Secure user application assembled). . . . . . . . . . 170
Figure 142. Application boot path:
(OEM-iRoT and Secure/Non-Secure user application assembled) . . . . . . . . . . . . . . . . . 170
Figure 143. Select the device or board . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 171
Figure 144. Select the STM32H5 device . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 172
Figure 145. Peripheral initialization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 172
1 STM32Cube overview
a. Arm is a registered trademark of Arm Limited (or its subsidiaries) in the US and/or elsewhere.
2.1 Principles
Customers need to quickly identify the MCU that best meets their requirements (core
architecture, features, memory size, performance…). While board designers main concerns
are to optimize the microcontroller pin configuration for their board layout and to fulfill the
application requirements (choice of peripherals operating modes), embedded system
developers are more interested in developing new applications for a specific target device,
and migrating existing designs to different microcontrollers.
The time taken to migrate to new platforms and update the C code to new firmware drivers
adds unnecessary delays to the project. STM32CubeMX was developed within STM32Cube
initiative which purpose is to meet customer key requirements to maximize software reuse
and minimize the time to create the target system:
• Software reuse and application design portability are achieved through STM32Cube
firmware solution proposing a common Hardware Abstraction Layer API across STM32
portfolio.
• Optimized migration time is achieved thanks to STM32CubeMX built-in knowledge of
STM32 microcontrollers, peripherals and middleware (LwIP and USB communication
protocol stacks, FatFs file system for small embedded systems, FreeRTOS).
STM32CubeMX graphical interface performs the following functions:
• Fast and easy configuration of the MCU pins, clock tree and operating modes for the
selected peripherals and middleware
• Generation of pin configuration report for board designers
• Generation of a complete project with all the necessary libraries and initialization C
code to set up the device in the user defined operating mode. The project can be
directly open in the selected application development environment (for a selection of
supported IDEs) to proceed with application development (see Figure 1).
During the configuration process, STM32CubeMX detects conflicts and invalid settings and
highlights them through meaningful icons and useful tool tips.
packages enhanced for STM32CubeMX. It can be launched from the ST Tools tab
found in STM32CubeMX Tools view.
• Contextual help
Contextual help windows can be displayed by hovering the mouse over Cores, Series,
Peripherals and Middleware. They provide a short description and links to the relevant
documentation corresponding to the selected item.
• Access to ST tools
From STM32CubeMX project, the Tools tab allows the user to launch Tools directly or
to access tools download pages on www.st.com.
• Video tutorials
STM32CubeMX allows the user to browse and play video tutorials. The video tutorial
browser is accessible from the Help menu.
Versions earlier than STM32CubeMX V6.2.0 require a JRE to be installed. The JRE version
constraints are:
• 64-bit version mandatory, 32-bit version not supported
• the STM32PackCreator companion tool requires JRE supporting JavaFX
• minimum JRE version is 1.8_45 (known limitation with 1.8_251)
• version 11 is supported, versions 7, 9, 10, 12 and upper are not supported
STMicroelectronics promotes the use of the following JREs:
• Oracle(a), subject to license fee
• Amazon Corretto™(a), no-cost solution based on OpenJDK, JDK installer
recommended.
STM32CubeMX operation is not guaranteed with other JREs.
a. Oracle and Java are registered trademarks of Oracle and/or its affiliates.
a. All other trademarks are the properties of their respective owners.
On Linux:
a) On STM32CubeMX-Lin line, Click “Get software” to download the package
b) Extract (unzip) the downloaded package.
c) Make sure you have administrator rights to access the target installation directory.
You can run the installation as root (or sudo) to install STM32CubeMX in shared
directories.
d) Do chmod 777 SetupSTM32CubeMX-VERSION to change the properties, so
that the file is executable.
e) Double-click on the SetupSTM32CubeMX-VERSION file, or launch it from the
console window.
On macOS:
a) On STM32CubeMX-Mac line, Click “Get software” to download the package
b) Extract (unzip) the downloaded package.
c) Make sure you have administrator rights.
d) Double-click SetupSTM32CubeMX-VERSION.app application file to launch the
installation wizard.
In case of error, try to fix it: - $sudo xattr -cr <Folder where the zip was extracted>
Interactive mode
To perform interactive installation, proceed as follows:
1. extract (unzip) to folder the auto-extract installation file (SetupSTM32CubeMX-
VERSION-Win.exe)
2. open a console window with administrator rights
3. go to the extracted folder (cd <folder path>)
4. run the command jre\bin\java -jar SetupSTM32CubeMX-<VERSION>.exe -
console
Auto-install mode
At end of an installation, performed either using STM32CubeMX graphical wizard or console
mode, it is possible to generate an auto-installation script containing user preferences (see
Figure 4).
You can then launch the installation by typing, from a console window with administrator
rights, the following command:
SetupSTM32CubeMX-VERSION-Win.exe ABSOLUTE_PATH_TO_AUTO_INSTALL.xml
Several proxy types exist and different computer network configurations are possible:
• Without proxy: the application directly accesses the web (Windows default
configuration).
• Proxy without login/password
• Proxy with login/password: when using an Internet browser, a dialog box opens and
prompts the user to enter its login/password.
• Web proxies with login/password: when using an Internet browser, a web page opens
and prompts the user to enter its login/password.
If needed, contact your IT administrator for proxy information (proxy type, http address,
port).
STM32CubeMX does not support web proxies. In this case, the user cannot benefit from the
update mechanism and must manually copy the STM32Cube MCU packages from
http://www.st.com/stm32cube to the repository. To do it, follow the sequence below:
1. Go to http://www.st.com/stm32cube and download the relevant STM32Cube MCU
package from the Associated Software section.
2. Unzip the zip package to your STM32Cube repository. Find out the default repository
folder location in the Updater settings tab as shown in Figure 6 (you might need to
update it to use a different location or name).
3. In the Connection Parameters tab, specify the proxy server settings appropriate for
your network configuration by selecting a proxy type among the following possibilities
(see Figure 7):
– No Proxy
– Use System Proxy Parameters
On Windows, proxy parameters are retrieved from the PC system settings.
Uncheck “Require Authentication” if a proxy server without login/password
configuration is used.
6. Select Help > Install New Libraries submenu to select among a list of possible
packages to install.
7. If the tool is configured for manual checks, select Help > Check for Updates to find out
about new tool versions or firmware library patches available to install.
2. Click From Local … button to browse the computer filesystem and select an
embedded software package. STM32Cube MCU packages come as zip archives and
embedded software packs come as .pack archives.
This action is required in the following cases:
– No Internet access is possible but the embedded software package is available
locally on the computer.
– The embedded software package is not public and hence not available on
Internet. For such packages, STM32CubeMX cannot detect and propose updates.
3. Click From URL… button to specify the download location from Internet for either one
of the pack .pdsc file or the vendor pack index (.pidx).
Proceed as follow:
a) Choose From URL … and click New (see Figure 10).
b) Specify the .pdsc file url. As an example, the url of Oryx-Embedded middleware
pack is https://www.oryx-embedded.com/download/pack/Oryx-
Embedded.Middleware.pdsc (see Figure 11).
c) Click the Check button to verify that the provided url is valid (see Figure 11).
d) Click OK. The pack pdsc information is now available in the user defined pack list
(see Figure 12).
To delete a url from the list, select the url checkbox and click Remove.
e) Click OK to close the window and start retrieving psdc information. Upon
successful completion, the available pack versions are shown in the list of libraries
that can be installed. Use the corresponding checkbox to select a given release.
f) Click Install Now to start downloading the software pack. A progress bar opens to
indicate the installation progress. If the pack comes with a license agreement, a
window pops up to ask for user’s acceptance (see Figure 14). When the
installation is successful, the check box turns green (see Figure 15).
The user can then add software components from this pack to its projects.
STM32CubeMX user interface comes with three main views the user can navigate through
using convenient breadcrumbs:
1. the Home page
2. the New project window
3. the project page
They come with panels, buttons and menus allowing users to take actions and make
configuration choices with a single click.
The user interface is detailed in the following sections.
For C code generation, although the user can switch back and forth between the different
configuration views, it is recommended to follow the sequence below:
1. From the Project Manager view, configure the project settings.
2. From the Mode panel in the Pinout & Configuration view, configure the RCC
peripheral by enabling the external clocks, master output clocks, audio input clocks
(when relevant for your application). This automatically displays more options on the
Clock configuration view (see Figure 97). Then, select the features (peripherals,
middlewares) and their operating modes relevant to the application.
3. If necessary, adjust the clock tree configuration from the clock configuration view.
4. From the Configuration panel in the Pinout & Configuration view configure the
parameters required to initialize the peripherals and middleware operating modes.
5. Generate the initialization C code by clicking .
1. On New project: to avoid any popup error messages at this stage, make sure an Internet connection is available
(Connection Parameters tab under Help > Updater settings menu) or that Data Auto-refresh settings are set to No
Auto-Refresh at application start (Updater Settings tab under Help > Updater Settings menu).
2. On Import, a status window displays the warnings or errors detected when checking for import conflicts. The user can then
decide to cancel the import.
Caution: On project load: STM32CubeMX detects if the project was created with an older version of
the tool and if this is the case, it proposes the user to either migrate to use the latest
STM32CubeMX database and STM32Cube firmware version, or to continue.
Prior to STM32CubeMX 4.17, clicking Continue still upgrades to the latest database
“compatible” with the SMT32Cube firmware version used by the project.
Starting from STM32CubeMX 4.17, clicking Continue keeps the database used to create the
project untouched. If the required database version is not available on the computer, it is
automatically downloaded.
When upgrading to a new version of STM32CubeMX, make sure to always backup your
projects before loading the new project (especially when the project includes user code).
Help
Opens the STM32CubeMX user manual. None
F1
About
Shows version information. None
Alt-A
Docs & Resources Displays the official documentation available for
None
Alt-D the MCU used in the current project.
Opens the Video Tutorial browser that proposes a
Video Tutorials
list of videos and allows the user to launch a video None
Alt-V
in one click.
Opens a dialog window that proposes to refresh
STM32CubeMX database with STM32 MCU latest
Refresh Data
information (description and list of official None
Alt-R
documents), and allows the user to download of
all official documentation in one shot.
Check for Updates Shows the software and firmware release updates
Click
Alt-C available for download.
Shows all the embedded software packages
available for installation.
Manage embedded
A green check box indicates that the package is
software packages Click
already installed in the user repository folder (the
Alt-U
repository folder location is specified under
Help > Updater Settings menu).
Opens the updater settings window to configure
manual versus automatic updates, proxy settings
Updater Settings…
for Internet connections, repository folder where None
Alt-S
the downloaded software and firmware releases
will be stored.
Opens the user preference window to enable or
User Preferences None
disable collect of features usage statistics.
The main purpose is to select from the STM32 portfolio the microcontroller or board that
best fits the user application needs, or simply to get started using an example project.
This window shows three tabs to choose from:
• an MCU selector tab (offering a list of target processors)
• a Board selector tab (showing a list of STMicroelectronics boards)
• an Example selector tab (allows the user to browse and open an example project)
The new project window also features a Cross selector tab (allows the user to find, for a
given MCU/MPU part number and for a set of criteria, the best replacement within the
STM32 portfolio)
For the STM32L5 series the security features of the Arm Cortex-M33 processor and its
Arm® TrustZone® for Armv8-M are combined with ST security implementation. Selecting an
STM32L5 MCU or board requires to choose whether to activate Arm® TrustZone®
(hardware security) or not (see Figure 25). The project is adjusted accordingly:
• if Arm® TrustZone® is not activated, the solution is the same as for other STM32Lx
series
• if Arm® TrustZone® is activated, the project configuration and the generated project
shows specificities related to the security features (refer to dedicated sections in this
manual).
Figure 29. New Project window - MCU list with close function
Note: A matching percentage is computed for each user selected criteria, for example:
- When requesting four instances of the CAN peripheral, MCUs with only three instances
reach a 75% match on the CAN criteria
- If the maximum price criteria is selected, the matching ratio for a given MCU is the
maximum requested price divided by the actual MCU price. In the case of a minimum price
criteria, the matching ratio is the MCU price divided by the minimum requested price.
Finally, all criteria ratios are averaged to give the Match column percentage value.
Selecting an example and clicking "Start project" allows STM32CubeMX to copy the
example as a new project (the user can change the default location at this stage).
Warning: For some examples the "Start Project" button is shown with
an "Under Development" warning icon. Projects created from
these examples may be not functional (they do not compile).
Fixes are in development.
Several options are available to open the newly created project (see Figure 33):
• with STM32CubeMX (available only for examples listed with a CubeMX version set)
• with a File explorer
• with one of the supported toolchains (provided the toolchain is already installed on your
computer)
Note: If the STM32Cube MCU package necessary for the example is missing from the repository
STM32CubeMX automatically starts the download process.
Clicking “ACCESS TO CROSS SELECTOR” under the “Start my project from Cross
Selector” section of the main page opens the New Project window on the Cross selector tab.
Two drop downs menus allow the user to select the vendor and the part number of the
product to be compared to (see Figure 35). A part number can also be entered partially:
STM32CubeMX proposes a list of matching products (see Figure 36).
Compare cart
Once a part number is selected, a list of matching ST part number candidates is displayed
along with their matching ratio in the Matching ST candidates panel.
By default, the three closest matches are selected and added to the compare cart along with
the part number to be compared to (see Figure 37).
Buttons are available to manipulate and save a copy of the compare cart view:
• to hide criteria that are not used for the comparison or show all criteria.
• to come back to default STM32CubeMX comparison settings
• to copy and paste the current cart view in a document or email.
Figure 38. Cross selector - Part number selection for a new project
Clicking the Cross Selector Tab allows the user to go back to the cart and change the
current selection for another part number.
locations:
• to the home page by clicking the Home breadcrumb
• to the new project window by clicking the part number
• back to the project page by clicking the project name (or Untitled if the project does not
have a name yet).
Selecting a board, then answering No in the dialog window requesting to initialize all
peripherals to their default mode, automatically sets the pinout for this board. However, only
the pins set as GPIOs are marked as configured, i.e. highlighted in green, while no
peripheral mode is set. The user can then manually select from the peripheral tree the
peripheral modes required for its application (see Figure 40).
Figure 40. STM32CubeMX Main window upon board selection (peripherals not initialized)
Selecting a board and accepting to initialize all peripherals to their default mode
automatically sets both the pinout and the default modes for the peripherals available on the
board. This means that STM32CubeMX generates the C initialization code for all the
peripherals available on the board and not only for those relevant to the user application
(see Figure 41).
buttons allow opening the configuration options for the given component (Mode and
Configuration panels). The button icon color reflects the status of the configuration
status.
• A Software Packs menu with two sub-menus:
– Select Components to select, for the current project, software components not
available by default. This selection updates the Pinout & Configuration view
accordingly
– Manage Software Packs to install/uninstall software packs.
• An Additional Software function that allows to select, for the current project, software
components that are not available by default. Selecting an additional software
component updates the Pinout & Configuration view accordingly.
• A Pinout menu that allows the user to perform pinout related actions such as clear
pinout configuration or export pinout configuration as csv file.
Tips
• You can resize the different panels at will: hovering the mouse over a panel border
displays a two-ended arrow: right-click and pull in a direction to either extend or reduce
the panel.
• You can show/hide the Configuration, Mode, Pinout and System views using the
open and close arrows.
Contextual help
The Contextual Help window is displayed when hovering the mouse over a peripheral or a
middleware short name.
By default, the window displays the extended name and source of configuration conflicts if
any (see Figure 42).
Clicking the details and documentation link (or CTRL+d) provides additional information
such as summary and reference documentation links (see Figure 43). For a given
FatFs code without a predefined peripheral mode. Then, it is up to the user to connect the
middleware with a user-defined peripheral by updating the generated user_diskio.c/.h driver
files with the necessary code.
The Pinout view is automatically refreshed to match the user’s component configuration
performed in the Mode panel.
Assigning pins directly through the Pinout view instead of the Mode panel requires a good
knowledge of the MCU since each individual pin can be assigned to a specific function.
Provides a list of MCUs that best match the pin configuration of the
current project. The matching can be:
– An exact match
– A partial match with hardware compatibility: pin locations are the
List Pinout Compatible MCUs Alt-L same, pin names may have been changed
– A partial match without hardware compatibility: all signals can be
mapped but not all at the same pin location
Refer to Section 15: Tutorial 5: Exporting current project configuration
to a compatible MCU.
Export pinout Generates pin configuration as a .csv text file including alternate
-
with Alternate functions functions information.
Export pinout Generates pin configuration as a .csv text file excluding alternate
Ctrl-U
without Alternate functions functions information.
Opens a window to specify the number of GPIOs to be freed among
Reset used GPIOs Alt-G
the total number of GPIO pins that are configured.
Opens a window to specify the number of GPIOs to be configured
among the total number of GPIO pins that are not used yet.
Specify their mode: Input, Output or Analog (recommended
Set unused GPIOs Ctrl-G configuration to optimize power consumption).
Caution: Before using this menu, make sure that debug pins
(available under SYS peripheral) are set to access
microcontroller debug facilities.
Layout reset - -
This Search field allows the user to search the Pinout view for a pin
name, a signal name, a signal label or an alternate pin name
- When it is found, the pin or set of pins matching the search criteria
blinks on the Pinout view.
Click the Pinout view to stop blinking.
Tip
If a mode becomes unavailable (highlighted in fuchsia), try to find another pin remapping
configuration for this mode by following the steps below:
1. From the Pinout view, deselect the assigned functions one by one until the mode
becomes available again.
2. Then, select the mode again and continue the pinout configuration with the new
sequence (see Appendix A: STM32CubeMX pin assignment rules for a remapping
example). This operation being time consuming, it is recommended to deselect the
Keep Current Signals Placement checkbox.
Note: Even if Keep Current Signals Placement is unchecked, GPIO_ functions (excepted
GPIO_EXTI functions) are not moved by STM32CubeMX.
STM32CUbeMX offers also an extended mode selected by right-clicking the pin: it allows to
select more than one signal per pin. This mode is meant for test purposes such as loopback
tests. It is to be used with caution as it can lead to electrical conflicts or increased power
consumption that can damage the device.
Configuration is invalid and needs to be fixed for the generated C project to be functional.
GPIO, DMA and NVIC settings can be accessed either via a dedicated button (like other
peripherals, or via a tab in the Configuration panel (see Figure 51).
Figure 51. Configuration window tabs (GPIO, DMA and NVIC settings for STM32F4 series)
Tooltip
Guides the user through the settings of
parameters with valid min-max range.
To display it, move the mouse over a
parameter value from a list of possible
values.
Search
No check option
By default, STM32CubeMX checks that the parameter values entered by the user are valid.
You can bypass this check by selecting the option No Check for a given parameter. This
allows entering you any value (such as a constant) that might not be known by
STM32CubeMX configuration.
The validity check can be bypassed only on parameters whose values are of integer type
(either hexadecimal or decimal). It cannot be bypassed on parameters coming from a
predefined list of possible values or on those which are of non-integer or text type.
To go back to the default mode (decimal or hexadecimal values with validity check enabled),
enter a decimal or hexadecimal value and check the relevant option (hexadecimal or
decimal check).
Caution: When a parameter depends upon another parameter that is set to No Check:
• Case of a parameter depending on another parameter for the evaluation of its minimum
or maximum possible value: If the other parameter is set to No Check, the minimum or
maximum value is no longer evaluated and checked.
• Case of a parameter depending on another parameter for the evaluation of its current
value: If the other parameter is set to No Check, the value is no longer automatically
derived. Instead, it is replaced with the formula text showing as variable the string of
the parameter set to No check (see Figure 53).
• When the constant is used for the configuration of a peripheral or middleware library
parameter. In this case, the user is requested to confirm the deletion since the constant
removal results in a invalid peripheral or middleware configuration (see Figure 59).
Figure 60. Consequence when deleting a user constant for peripheral configuration
Click on a row or select a set of rows to display the corresponding GPIO parameters:
• GPIO PIN state
It changes the default value of the GPIO Output level. It is set to low by default and can
be changed to high.
• GPIO mode (analog, input, output, alternate function)
Selecting a peripheral mode in the Pinout view automatically configures the pins with
the relevant alternate function and GPIO mode.
• GPIO pull-up/pull-down
It is set to a default value and can be configured when other choices are possible.
• GPIO maximum output speed (for communication peripherals only)
It is set to Low by default for power consumption optimization and can be changed to a
higher frequency to fit application requirements.
• User Label
It changes the default name (e.g. GPIO_input) into a user defined name. The Pinout
view is updated accordingly. The GPIO can be found under this new name via the Find
menu.
The Group by Peripherals checkbox allows the user to group all instances of a peripheral
under the same window (see Figure 64).
As shown in Figure 65, row multi-selection can be performed to change a set of pins to a
given configuration at the same time.
Selecting a DMA request automatically assigns a stream among all the streams available, a
direction and a priority. When the DMA channel is configured, it is up to the application code
to fully describe the DMA transfer run-time parameters such as the start address.
The DMA request (called channel for STM32F4 MCUs) is used to reserve a stream to
transfer data between peripherals and memories (see Figure 67). The stream priority is
used to decide which stream to select for the next DMA transfer.
DMA controllers support a dual priority system using the software priority first, and in case of
equal software priorities, a hardware priority that is given by the stream number.
Additional DMA configuration settings can be done through the DMA configuration
window:
• Mode: regular mode, circular mode, or peripheral flow controller mode (only available
for the SDIO peripheral).
• Increment Add: the type of peripheral address and memory address increment (fixed
or postincremented, in which case the address is incremented after each transfer).
Click the checkbox to enable the post-incremented mode.
• Peripheral data width: 8, 16, or 32 bits
• Switching from the default direct mode to the FIFO mode with programmable threshold:
a) Click the Use FIFO checkbox.
b) Configure the peripheral and memory data width (8, 16, or 32 bits).
c) Select between single transfer and burst transfer. If you select burst transfer,
choose a burst size (1, 4, 8, or 16).
In case of memory-to-memory transfer (MemToMem), the DMA configuration applies to a
source memory and to a destination memory.
Peripheral dedicated interrupts can also be accessed through the NVIC window in the
configuration window (see Figure 71).
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
GPIO_InitStruct.Alternate = GPIO_AF9_CAN1;
HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);
For some peripherals, the application still needs to call another function to actually
activate the interruptions. Taking the timer peripheral as an example, the
HAL_TIM_IC_Start_IT function needs to be called to start the Timer input capture (IC)
measurement in interrupt mode.
• Configuration of interrupts initialization sequence
Checking Select for Init sequence ordering for a set of peripherals moves the
HAL_NVIC function calls for each peripheral to a same dedicated function, named
MX_NVIC_Init, defined in the main.c. Moreover, the HAL_NVIC functions for each
peripheral are called in the order specified in the Code generation view bottom part
(see Figure 73).
As an example, the configuration shown in Figure 73 generates the following code:
/** NVIC Configuration
*/
void MX_NVIC_Init(void)
{
/* CAN1_TX_IRQn interrupt configuration */
HAL_NVIC_SetPriority(CAN1_TX_IRQn, 2, 2);
HAL_NVIC_EnableIRQ(CAN1_TX_IRQn);
/* PVD_IRQn interrupt configuration */
HAL_NVIC_SetPriority(PVD_IRQn, 0, 0);
HAL_NVIC_EnableIRQ(PVD_IRQn);
/* FLASH_IRQn interrupt configuration */
HAL_NVIC_SetPriority(FLASH_IRQn, 0, 0);
HAL_NVIC_EnableIRQ(CAN1_IRQn);
/* RCC_IRQn interrupt configuration */
HAL_NVIC_SetPriority(RCC_IRQn, 0, 0);
HAL_NVIC_EnableIRQ(CAN1_IRQn);
/* ADC_IRQn interrupt configuration */
HAL_NVIC_SetPriority(ADC_IRQn, 0, 0);
HAL_NVIC_EnableIRQ(ADC_IRQn);
}
• Interrupts handler code generation
By default, STM32CubeMX generates interrupt handlers within the stm32xxx_it.c file.
As an example:
void NMI_Handler(void)
{
HAL_RCC_NMI_IRQHandler();
}
void CAN1_TX_IRQHandler(void)
{
HAL_CAN_IRQHandler(&hcan1);
}
The column Generate IRQ Handler allows the user to control whether the interrupt
handler function call can be generated or not. Deselecting CAN1_TX and NMI
interrupts from the Generate IRQ Handler column as shown in Figure 73 removes the
code mentioned earlier from the stm32xxx_it.c file.
• Tasks
Under the Tasks section, click the Add button to open the New Task window where
task name, priority, stack size and entry function can be configured (see Figure 76).
These settings can be updated at any time: double-clicking a task row opens again the
new task window for editing.
The entry function can be generated as weak or external:
– When the task is generated as weak, the user can propose a definition different
from the one generated by default.
– When the task is extern, it is up to the user to provide its function definition.
By default, the function definition is generated including user sections to allow
customization.
• Queues
Under the Queues section, click the Add button to open the New Queue window
where the queue name, size and item size can be configured (see Figure 76). The
queue size corresponds to the maximum number of items that the queue can hold at a
time, while the item size is the size of each data item stored in the queue. The item size
can be expressed either in number of bytes or as a data type:
• 1 byte for uint8_t, int8_t, char and portCHAR types
• 2 bytes for uint16_t, int16_t, short and portSHORT types
• 4 bytes for uint32_t, int32_t, int, long and float
• 8 bytes for uint64_t, int64_t and double
By default, the FreeRTOS heap usage calculator uses four bytes when the item size
cannot be automatically derived from user input.
These settings can be updated at any time: double-clicking a queue row opens again
the new queue window for editing.
The following code snippet shows the generated code corresponding to Figure 75.
/* Create the thread(s) */
/* definition and creation of defaultTask */
osThreadDef(defaultTask, StartDefaultTask, osPriorityNormal, 0, 128);
defaultTaskHandle = osThreadCreate(osThread(defaultTask), NULL);
Under each object dedicated section, clicking the Add button to open the corresponding
New <object> window where the object specific parameters can be specified. Object
settings can be modified at any time: double- clicking the relevant row opens again the New
<object> window for edition.
Note: Expand the window if the newly created objects are not visible.
• Timers
Prior to creating timers, their usage (USE_TIMERS definition) must be enabled in the
software timer definitions section of the Configuration parameters tab. In the
same section, timer task priority, queue length and stack depth can be also configured.
The timer can be created to be one-shot (run once) or auto-reload (periodic). The timer
name and the corresponding callback function name must be specified. It is up to the
user to fill the callback function code and to specify the timer period (time between the
timer being started and its callback function being executed) when calling the
CMSIS-RTOS osTimerStart function.
• Mutexes / Semaphores
Prior to creating mutexes, recursive mutexes and counting semaphores, their usage
(USE_ MUTEXES, USE_RECURSIVE_MUTEXES,
USE_COUNTING_SEMAPHORES definitions) must be enabled within the Kernel
settings section of the Configuration parameters tab.
The following code snippet shows the generated code corresponding to Figure 77.
When used as timebase source, a given peripheral is grayed and can no longer be selected
(see Figure 80).
As illustrated in the following examples, the selection of the HAL timebase source and the
use of FreeRTOS influence the generated code.
Figure 81. NVIC settings when using SysTick as HAL timebase, no FreeRTOS
Interrupt priorities (in main.c) and handler code (in stm32f4xx_it.c) are generated
accordingly:
• main.c file
/* SysTick_IRQn interrupt configuration */
HAL_NVIC_SetPriority(SysTick_IRQn, 0, 0);
• stm32f4xx_it.c file
/**
* @brief This function handles System tick timer.
*/
void SysTick_Handler(void)
{
/* USER CODE BEGIN SysTick_IRQn 0 */
/* USER CODE END SysTick_IRQn 0 */
HAL_IncTick();
HAL_SYSTICK_IRQHandler();
/* USER CODE BEGIN SysTick_IRQn 1 */
Figure 82. NVIC settings when using FreeRTOS and SysTick as HAL timebase
As shown in the code snippets below, the SysTick interrupt handler is updated to use
CMSIS-os osSystickHandler function.
• main.c file
/* SysTick_IRQn interrupt configuration */
HAL_NVIC_SetPriority(SysTick_IRQn, 15, 0);
• stm32f4xx_it.c file
/**
* @brief This function handles System tick timer.
*/
void SysTick_Handler(void)
{
/* USER CODE BEGIN SysTick_IRQn 0 */
Figure 83. NVIC settings when using FreeRTOS and TIM2 as HAL timebase
Assigning a component to a runtime context means specifying which context(s) will control
the component at runtime. Assignments to a Cortex-A7 context are reflected in the device
tree code generation, while assignments to the Cortex-M4 context are reflected in
STM32Cube based C code generation (refer to code generation sections for more details).
The component assignment to a context is done in the context dedicated column.
When a peripheral is set as boot device, it imposes a specific pinout: some signals have to
be mapped exclusively on pins visible by the boot ROM and only these signals/pins are
taken into account by the boot ROM program.
When a functional mode of a ROM-bootable peripheral is set, the pinout linked to this mode
is the same of that for a runtime context except for the signals imposed on specific pins by
the boot ROM code.
During the boot step (boot ROM code execution), the peripheral is running only with the
sub-set of bootable signals and pins. After boot, during runtime, the peripheral runs with all
signals necessary to the selected functional mode.
The Boot loader (A7 FSBL) column is used to define which devices can be managed during
this Boot loader stage.
This assignment are reflected in the different Device-Trees generated (refer to code
generation sections for more details).
For GPIOs (see Figure 88), assignment is done through the Pinout view directly or later and
automatically through its selection in the platform settings panel of a middleware.
4.7.1 Privilege access for peripherals, GPIO EXTIs and DMA requests
Independently of TrustZone®, STM32CubeMX enables privilege access:
• for each peripheral: in the GTZC configuration panel (see Section 4.7.5), as shown in
Figure 90
• for each GPIO EXTI: in the GPIO configuration panel, as shown in Figure 91
• for each DMA channel: in the DMA configuration panel (see Section 4.7.4), as shown in
Figure 92.
Note: When TrustZone® is active, either all or none of the RCC registers can be put in privilege
mode. In STM32CubeMX, this is done by selecting “Privileged-only attribute” check box
from RCC mode panel (see Figure 93). In privilege mode, all RCC registers configuration
are reserved for the privilege application through the PWR_CR_PRIVEN bit, which is
secured when Trustzone® is activated.
The DMA channel is set to non-privileged by default. The choice to set it as privileged is
always available.
The choice to secure the DMA channel, source, and destination depends on the request
characteristics.
There are four cases:
• The request is either a memory to memory transfer request or a DMA generator
request: the channel is not secure by default but can be secured. The source and
destination can be secured only when the channel is secure.
• The request is for a peripheral assigned to the non-secure context: channel, source
and destination cannot be secured (checkboxes are disabled) and so they are forced to
the non-secure context.
• The request is a peripheral to memory request for a peripheral assigned to the secure
context: channel and source are automatically secured (checkboxes enabled, cannot
be disabled), while there is a choice to secure or not the destination.
• The request is a memory to peripheral request for a peripheral assigned to the secure
context: channel and destination are automatically secured (checkboxes enabled,
cannot be disabled), while there is a choice to secure or not the source.
4.7.5 GTZC
To configure TrustZone® system security, STM32L5 series come with a Global TrustZone®
security controller (GTZC). Refer to reference manual RM0438 for more details.
In STM32CubeMX, for projects with TrustZone® activated, GTZC is enabled by default and
cannot be disabled. For projects without Trustzone® active, GTZC can be enabled and
gives only the possibility to set privileges.
GTZC is made up of three blocks that can be configured through CubeMX using dedicated
tabs in GTZC configuration panel:
• TZSC (TrustZone® security controller)
– Defines which peripherals are secured and/or privileged, and controls the
non-secure area size for the watermark memory peripheral controller (MPCWM).
The TZSC block informs some peripherals (such as RCC or GPIOs) about the
secure status of each securable peripheral, by sharing with RCC and I/O logic.
– The privileges are set in the TrustZone® Security Controller – Privilegeable
Peripherals tab.
– The secure states are set in TrustZone® Security Controller – Securable
Peripherals tab (they match the assignment to context (M33S or M33NS) done on
the Tree view or in the Mode panel).
– The MPCWM configuration is done through the TrustZone® Security Controller –
Memory Protection Controller Watermark tab.
• MPCBB (block-based memory protection controller)
– Controls secure states of all blocks (256-byte pages) of the associated SRAM. It is
configured through the Block-based Memory Protection Controller tab.
• TZIC (TrustZone® illegal access controller)
– Gathers all illegal access events in the system and generates a secure interrupt
towards NVIC. It is configured through the TrustZone® Illegal Access Controller
tab.
4.7.6 OTFDEC
On-the-fly decryption engine (OTFDEC) allows the user to decrypt on-the-fly AHB traffic
based on the read request address information. When security is enabled in the product
OTFDEC can be programmed only by a secure host.
Actual clock speeds are displayed and active. The use clock signals are highlighted in blue.
Reverse path is supported: just enter the required clock speed in the blue filed and
STM32CubeMX attempts to reconfigure multipliers and dividers to provide the requested
value. The resulting clock value can then be locked by right clicking the field to prevent
modifications.
STM32CubeMX generates the corresponding initialization code:
• main.c with relevant HAL_RCC structure initializations and function calls
• stm32xxxx_hal_conf.h for oscillator frequencies and VDD values.
d) Finally, iterating through multiplier/dividers values to fix the issue. The clock tree is
cleared from fuchsia highlights if a solution is found, otherwise an error message
is displayed.
Note: To be available from the clock tree, external clocks, I2S input clock, and master clocks must
be enabled in RCC configuration in the Pinout view. This information is also available as
tooltips.
The tool automatically performs the following operations:
• Adjust bus frequencies, timers, peripherals and master output clocks according to user
selection of clock sources, clock frequencies and prescalers/multipliers/dividers values.
• Check the validity of user settings.
• Highlight invalid settings in fuchsia and provide tooltips to guide the user to achieve a
valid configuration.
The Clock Configuration view is adjusted according to the RCC settings (configured in
RCC Pinout & Configuration views) and vice versa:
• If in RCC Pinout view, the external and output clocks are enabled, they become
configurable in the Clock Configuration view.
• If in RCC Configuration view, the Timer prescaler is enabled, the choice of Timer clocks
multipliers is adjusted.
Conversely, the clock tree configuration may affect some RCC parameters in the
configuration view:
• Flash latency: number of wait states automatically derived from VDD voltage, HCLK
frequency, and power over-drive state.
• Power regulator voltage scale: automatically derived from HCLK frequency.
• Power over-drive is enabled automatically according to HCLK frequency. When the
power drive is enabled, the maximum possible frequency values for AHB and APB
domains are increased. They are displayed in the Clock Configuration view.
The default optimal system settings that is used at startup are defined in the
system_stm32f4xx.c file. This file is copied by STM32CubeMX from the STM32CubeF4
MCU package. The switch to user defined clock settings is done afterwards in the main
function.
Figure 97 gives an example of Clock tree configuration for an STM32F429x MCU, and
Table 9 describes the widgets that can be used to configure each clock.
Multiplier selection
In the Clock Configuration view, these securable resources are highlighted with a key icon.
Security is enabled using the Secure checkbox accessed through a right-click on the
resource. Once the resource is secure, it is highlighted with a green square.
Configurable resources can be locked to prevent further configuration changes: this is done
by selecting the Lock checkbox accessed through a right-click on the resource.
There is also a shortcut button to lock/unlock in one click all resources that are both
securable and configurable.
When a peripheral is configured as secure, its related clock, reset, clock source and clock
enable are also secure. In STM32CubeMX the peripheral is configured as secure in the
Pinout & Configuration view and its clock source is automatically highlighted as secure
using a green square in the Clock configuration view.
Example of the system clock HSE clock source that is secured and
remains open for editing: the frequency value can be changed.
Example of the system clock HSE clock source that is secured and has
been locked for editing: the frequency value cannot be modified.
Example of the main PLL multiplexer that is secured and locked. The
clock source is HSE and cannot be changed. PLLxxM, PLLxxN, PLLxxP,
PLLxxQ and PLLxxR are secured and locked for editing as well.
Example of securing and locking the access to AHB prescaler. APB1 and
APB2 prescalers are locked as well.
4.8.3 Recommendations
The Clock Configuration view is not the only entry for clock configuration, RCC and RTC
peripherals can also be configured.
1. From the Pinout & Configuration view, go to the RCC mode panel to enable the
clocks as needed: external clocks, master output clocks and Audio I2S input clock
when available. Then go to the RCC configuration panel, and adjust the default settings
if needed. Changes are reflected in the Clock Configuration view. The defined
settings may change the settings in the RCC configuration as well (see Figure 99).
Figure 99. Clock tree configuration: enabling RTC, RCC clock source
and outputs from Pinout view
2. Go to the RCC configuration in the Pinout & Configuration view. The settings
defined there for advanced configurations are reflected in the Clock configuration
view. The defined settings may change the settings in the RCC configuration.
Table 11. Voltage scaling versus power over-drive and HCLK frequency
Parameter STM32CubeMX panel Value
Table 12 gives the relations between power-over drive mode and HCLK frequency.
Scale 3
≤120 MHz
POD is disabled
Scale 2
120 to 144 MHz
POD can be either disabled or enabled
Scale 1 when POD is disabled
144 to 168 MHz
Scale 2 when POD is enabled
POD must be enabled
168 to 180 MHz Scale 1 (otherwise frequency range not
supported)
HSI High speed Internal oscillator: enabled after reset, lower accuracy than HSE
HSE High speed external oscillator: requires an external clock circuit
PLL Phase locked loop: used to multiply above clock sources
LSI Low speed Internal clock: low power clocks usually used for watchdog timers
The code is generated in the project folder tree shown in Figure 102.
Note: Some project settings options become read-only once the project is saved. To modify these
options, the project must be saved as a new project using the File> Save Project as menu.
The new location must contain at least a Drivers directory containing the HAL and
CMSIS drivers from the relevant STM32Cube MCU package. An error message pops
up if the folders cannot be found (see Figure 107).
To reuse the same Drivers folder across all projects that use the same firmware
location, select the Add the library files as reference from the Code generator tab
allows (see Figure 108).
Caution: STM32CubeMX manages firmware updates solely for this default location. Choosing
another location prevents the user from benefiting from automatic updates. The user must
manually copy new driver versions to its project folder.
Choosing between HAL and LL based code generation for a given peripheral
instance
Starting from STM32CubeMX 4.17 and STM32L4 series, STM32CubeMX offers the
possibility for some peripherals to generate initialization code based on Low Layer (LL)
drivers instead of HAL drivers: the user can choose between LL and HAL driver in the
Driver Selector section. The code is generated accordingly (see Section 6.2: STM32Cube
code generation using Low Layer drivers).
Unselecting the Visibility (Static) option, as shown for MX_I2C1_init function in Figure 112,
allows the generation of the function definition without the static keyword, and hence
extends its visibility outside the current file (see Figure 113).
Conflicts can occur when importing a smaller package with less pins or a lower-end
MCU with less peripheral options.
Click the Try Import button to check for such conflicts: the Import Status window and
the Peripheral list get refreshed to indicate errors (see Figure 116), warnings and
whether the import has been successful or not:
– Warning icons indicate that the user has selected a peripheral instance more than
once, and that one of the import requests will not be performed.
– A cross sign indicates that there is a pinout conflict, and that the configuration
cannot be imported as such.
The manual import can be used to refine import choices and resolve the issues raised
by the import trial. Figure 117 gives an example of successful import trial, obtained by
deselecting the import request for some peripherals.
The Show View function allows switching between the different configuration tabs
(pinout, clock tree, peripheral configuration) for checking influence of the “Try Import”
action before actual deployment on current project (see Figure 117).
3. Choose OK to import with the current status or Cancel to go back to the empty project
without importing.
Upon import, the Import icon gets grayed since the MCU is now configured and it is no
more possible to import a non-empty configuration.
• Select Pinout > Reset used GPIOs from the STM32CubeMX menu bar.
Depending whether the Keep Current Signals Placement option is checked or not on
the toolbar, STM32CubeMX conflict solver is able to move or not the GPIO signals to
other unused GPIOs:
– When Keep Current Signals Placement is off (unchecked), STM32CubeMX
conflict solver can move the GPIO signals to unused pins in order to fit in another
peripheral mode.
– When Keep Current Signals Placement is on (checked), GPIO signals is not
moved and the number of possible peripheral modes is limited.
Refer to Figure 120 and Figure 121 and check the limitation(s) in available peripheral
modes.
Figure 120. Set unused GPIO pins with Keep Current Signals Placement checked
Figure 121. Set unused GPIO pins with Keep Current Signals Placement unchecked
See Section 10: Support of additional software components using CMSIS-Pack standard for
more details on how to handle additional software components through STM32CubeMX
CMSIS-Pack integration.
Show only packs compatible with the MCU used for the current project.
Note: Some components, highlighted in gray in the component panel, are shown as read-only.
They are software components (HAL peripheral drivers or middleware offers) coming with
STM32Cube MCU embedded software package and are natively available in
STM32CubeMX.
The pack has been added to the user favorite list of packs.
Use the Details and Warnings panel to add/remove packs from list of favorites.
The pack version is not compatible with this STM32CubeMX version.
Solution: select a compatible version.
The pack version is not yet installed.
Solution: go to the Details and Warnings panel to download the pack version to use it
for a project.
The component is not available for selection.
Solution: download the pack this component belongs to.
A component is selected and at least one condition remains to be solved.
Select the line of the component with such icon to refresh the Component
dependencies panel with the list of dependencies, status and solutions if any found.
At least one component is selected and all conditions, if any, are met.
The panel is refreshed when selecting a component, providing details on the dependencies
to solve and the available solutions, if found (see Table 17):
• click the Show button to show the component solving the dependency
• click the Select button to select the component solving the dependency
• when available, click Resolve button to automatically resolve the dependencies.
No dependency to solve.
The Symbol view reflects the STM32CubeMX project pinout configuration and, optionally,
the labeling (see Figure 132). The downloaded CAD files are aligned with the pinout
configuration and optionally, with the labels as well.
IDE
Code compilation
Download on
Post-build command Code target
execution for code encryption Target
(provisioning)
DT56289
encryption via TPC
Note: STM32H56x and STM32H503 do not support cryptographic hardware accelerator (a feature
needed for the ST-iROT and ST-uROT), therefore the full spectrum of boot paths is not
available for these MCUs.
For details about boot path and its usage, read the wiki page available on www.st.com, and
the guide located under the Utilities folder of the STM32Cube firmware package.
This section details, through examples, how to configure a boot path and generate the
associated code. It includes compilation, encryption, and provisioning.
STM32H56x √ - - - -
STM32H57x √ - - - -
STM32H503x √ - - - -
STM32H56x √ √ - - -
STM32H57x √ √ √ √ √
1. S: secure, NS: non-secure.
The following figures indicate the boot paths that STM32CubeMX can configure, and the
entry points after reset.
The related user option bytes are configured automatically (through Trusted Package
Creator installed with CubeMX), and programmed during the provisioning stage.
Optional NS application
DT56285V2
= OEM-iRoT
OEM-iRoT OEM-uRoT
S application
DT56286V2
=1
TZEN OEM-iRoT OEM-uRoT
S application
Bootloader Bootloader
Debug authentication Debug authentication
ST-iRoT (secure boot) ST-iRoT (secure boot)
Reset
DT56291
ST SFI/RSS ST SFI/RSS
Figure 137. Application boot paths (OEM-iRoT and Secure manager projects)
2(0L5R7ĺ6HFXUH1RQVHFXUH 67L5R7ĺ67X5R7
user application ĺ6HFXUHPDQDJHUĺ
Non-secure user application
NS-user application NS-user application
User flash
Module S2
S-user application Module S1
Secure manager(*)
OEM-iRoT(*) ST-uRoT
Reset
System flash
Bootloader Bootloader
Debug authentication Debug authentication
ST-iRoT (secure boot) ST-iRoT (secure boot)
Reset
ST SFI/RSS ST SFI/RSS
DT56290
(*) Not generated by STM32CubeMX
67L5R7ĺ2(0X5R7
ĺProject execution (Assembled)
TLV MCU boot
GPIO toggle NS
User flash
GPIO toggle S
Header MCU boot
OEM-uRoT
Header MCU boot
System flash
Bootloader
Debug authentication
ST-iRoT (secure boot)
Reset
DT56421V1
ST SFI/RSS
67L5R7ĺ2(0X5R7
ĺSecure/Non-secure user application
NS-user application
S-user application
Bootloader
Debug authentication
DT56422V1
ST-iRoT (secure boot)
Reset
ST SFI/RSS
NS-User application
Single image
(Secure and Non-Secure)
S-User application
System flash
Bootloader
Debug authentication
DT56423V1
ST-iRoT (secure boot)
Reset
ST SFI/RSS
NS-User application
User flash
Single image
(Secure and Non-Secure)
S-User application
Not generated by
2(0X5R7 670&XEH0;
System flash
Bootloader
Debug authentication
DT56424V1
ST-iRoT (secure boot)
Reset
ST SFI/RSS
NS-User application
User flash
Single image
(Secure and Non-Secure)
S-User application
Not generated by
OEMiRoT STM32CubeMX
System flash
Bootloader
Debug authentication
DT56425V1
ST-iRoT (secure boot)
Reset
ST SFI/RSS
DT56292
Select STM32H5
Click to open the
DT56293V2
MCU/MPU selector
Click No
DT56294
If you click yes, there will be an error during the secure code compilation.
By default, all peripherals are set as secure, and the memory allocation for the secure code
(defined through the OEM-iRoT_boot application) is too small.
=0 =0
NS application
DT56295V2
OEM-iRoT
TZEN disabled S application
Select the option “With TrustZone” on the popup window, as shown below.
DT56296
Step 4: Overall configuration
Configure the application (Figure 149), then save the project (Figure 150).
S- and NS-application
code selected by default
IDE selection
DT56298V2
Firmware repository,
keep it for
STM32CubeMX
DT56302V2
DT56303V2
• Select OEM-iRoT for this example
Select OEM-iRoT
DT56304V2
DT56305V2
• All possible boot paths for the second stage are proposed according to the selected
device and project structure.
• Select “Secure Application”, it generates secure and non-secure codes.
DT56306V2
Complete boot
path displayed
DT56307V2
Note: If a selected boot path is not supported, a warning message is displayed, and the “FINISH”
button is grayed out.
DT56309V2
properties for the
OEM-iRoT project
OEMiRoT_Config.obk
file generated
DT56311
Key to encrypt firmware and data images
• The H5-Image Gen1 and Gen2 tabs indicate the location of the image configuration
files and the path of the binary input and output files. Keep the default settings.
DT56314V2
DT56316
Additional directories, including the IDE environment, are created.
DT56315
non-secure application
code have been generated
The S and NS applications can be developed using the generated code skeletons.
DT56317
xml configuration for secure application xml configuration for non-secure application
The secure code must be generated before the non-secure code. Compile each code
separately (right click on Project → Rebuild all). The secure and non-secure signed and
encrypted binaries are generated during the post build phase.
In the user environment, CubeMX has generated an env.bat file, containing the information
required for provisioning. Do not change this file.
A pop-up (see Figure 168) appears if you forget to compile the project OEMiRoT_Boot in
the CubeFW.
DT56310V2
• Click “FINISH”, the boot path configuration panel is displayed (see Figure 172), use it
to configure the application, then press the GENERATE CODE button to generate the
code for the selected toolchain
DT56333V2
DT56334V2
A secure application code is generated
• During provisioning, log files are generated to inform the user about the activity
• Follow the on-screen instructions (Figure 178)
In the user environment STM32CubeMX has generated an env.bat file containing the
required data for provisioning, do not change it.
• Updatable Root of Trust (uRoT) option is set by default and cannot be modified
• Click “FINISH”: the panel of boot path configuration is displayed (Figure 184), use it to
configure the boot path in the “Boot Path Settings” tab
• Press the “GENERATE CODE” button to generate the configuration code for the
selected toolchain
DT56336V2
Figure 186. Code is generated
DT56337
The non-secure application can be developed using the generated code skeletons.
Post build
command added
DT56338
Trusted Package Creator generates an encrypted binary
Depending upon the configuration, the code is generated, and the “Secure Manager API” is
added. Additional services (such as cryptography or initial attestation) can be added with
the middleware.
The tool chain supported for the boot path configuration are Keil and CubeIDE.
DT56420V1
Step 2: Compile OEMiROT_Boot project
• Open OEMiROT_Boot with your preferred tool chain, and recompile the project.
– The map.properties file is automatically updated
(CODE_IMAGE_ASSEMBLY=0x01)
– The image file (OEMiRoT_NS_Code_Image.xml) is automatically updated
(firmware area size)
DT56426V1
Figure 193. Boot path project
• Open the project folder. A Python script assembles both binaries (Secure, Non
Secure), then the TPC signs them:
– Assembled_OEMiRot_Boot_Path_Example_assembled.bin → File assembled by
the Python script
– Assembled_OEMiRot_Boot_Path_Example_enc_sign.hex → File signed by the
TPC
• The post build command is added only for the Non Secure project.
MMT updates the linker scripts only when the second toggle button is ON.
The applicative regions are saved into the user project even if the first toggle button is OFF.
Press the “Start Project” button, and then choose the “With TrustZone activated” option.
Choose the “Tools” tab followed by the “Memory Management” option to display the Memory
Management Tool (see Figure 215).
User interface
• The middle panel represents the memory, split into two columns: the left one is the
memory seen by the core(s), the right one the memory set-up for the application.
• In this example there are two projects, a secure and a non-secure one. The application
region allocated to the secure project is green, the non-secure application region is
pink. The reserved memory regions are gray.
• For the new project created under STM32CubeMX the tool creates the default
application region to generate a valid project.
Region information
• Clicking on a particular region in the Application Regions column shows the associated
details on the left hand side.
• You can choose to hide the name of the reserved region, or hide the Secure/Non
Secure indication close to the region name (the secure/non-secure indication is
indicated by the color).
In this example, on the Pinout & Configuration panel, CORTEX_M33, FLASH, and GTZC
are set, and correspond to the region configuration on the Memory Management Tool. They
are grayed out, as they cannot be modified.
When an IP is under MMT control, a tooltip provides the info shown in Figure 219.
When going back to the MMT, a new region corresponding to the added FMC is inserted.
Add a new region by pressing the plus button appearing in the white space when hovering
with the mouse.
To add another external memory, go to the Pinout & Configuration view and add the
OCTOSPI1 to Cortex-M33 Secure. Choose Single SPI, and specify “Device Size” and
“Device Type.”
In this example, the region just added must be adjusted: we want it to be allocated to the
non secure project, and to start in the middle of the RAM. By adjusting those values, the
expected results appear (see Figure 227). The color is now pink (non-secure) and the
region starts in the middle of the RAM (OctoSPI1).
Remap
For performance reasons, part of the application must run on the internal memory (much
faster than the external memory). To do so, remap the added external RAM to an available
internal memory region:
• Go to the “Pinout & Configuration” tab
• Enable ICACHE, select the “Memory address remap” tick box
• Select a region and set the memory size to 64 Mbytes
• Change the Remap address to 0x9000 0000
• Go back to the “Memory management Tool” tab. Region 0x9000 0000 is named with
Remapped with the amount of RAM previously selected.
The default regions cannot be removed, but can be resized. As an example, the FLASH is
where the application code is hosted. You cannot untick the “Default Region.”
Changing the security of an application region mapped on aliased RAM or FLASH moves it
in an aliased RAM or FLASH corresponding to the new security setting. Graphically, the
region moves up and down, depending on the area it will go, as the same physical memory
is seen by the core at different locations.
Code generation
• Go to the project manager, set a name to your project, Choose CubeIDE as a toolchain
and press “GENERATE CODE”
• Navigate to the generated Secure Project and open the linker definition file. Under the
Memories definition you will see the defined memories with their start address and
length. This file shows only the secure regions in green. Open the non-secure linker file
and check the same location for the memory regions allocated to the non-secure area.
5 STM32CubeMX tools
Adding a step
There are two ways to add a new step:
• Click Add in the Power Consumption panel. The New Step window opens with empty
step settings.
• Or, select a step from the sequence table and click Duplicate. A New Step window
opens duplicating the step settings (see Figure 242).
Once a step is configured, resulting current consumption and TAMAX values are provided in
the window.
Editing a step
To edit a step, double-click it in the sequence table, this opens the Edit Step window.
Moving a step
By default, a new step is added at the end of a sequence. Click the step in the sequence
table to select it and use the Up and Down buttons to move it elsewhere in the sequence.
Deleting a step
Select the step to be deleted and click the Delete button.
Using interpolation
For steps configured for active modes (Run, Sleep), frequency interpolation is supported by
selecting CPU frequency as User Defined and entering a frequency in Hz (see Figure 246).
Importing pinout
Figure 247 illustrates the example of the ADC configuration in the Pinout view: clicking
Enable IPs from Pinout in the Power Consumption Calculator view selects the ADC
peripheral and GPIO A (Figure 248).
The Enable IPs from Pinout button allows the user to automatically select the peripherals
that have been configured in the Pinout view.
The user can select the peripherals relevant for the application:
– none (Disable All)
– some (using peripheral dedicated checkbox)
– all (Activate All)
– or all from the previously defined pinout configuration (Import Pinout).
Only the selected and enabled peripherals are taken into account when computing the
power consumption.
• Step duration
The user can change the default step duration value. When building a sequence, the
user can either create steps according to the application actual power sequence or
define them as a percentage spent in each mode. For example, if an application
spends 30% in Run mode, 20% in Sleep and 50% in Stop, the user must configure a
3-step sequence consisting in 30 ms in Run, 20 ms in Sleep and 50 ms in Stop.
• Additional Consumption
This field allows entering an additional consumption resulting from specific user
configuration (e.g. MCU providing power supply to other connected devices).
Figure 257. Current project configuration updated with new SMPS model
Figure 258. SMPS database management window with new model selected
Figure 259. SMPS transition checker and state diagram helper window
The BLE mode can be selected from the left panel and configured to reflect the user’s
application relevant settings. For each new step enabling BLE, the peripheral consumption
part is updated accordingly (see Figure 262). A similar approach is used for ZigBee (see
Figure 263).
Clicking “Load Example N” loads the sequence corresponding to the example N (see
Figure 266).
The example can be changed anytime: the new sequence can be either added to the
current sequence, or replace it (see Figure 267).
Note: The examples are provided for a given part number and may require adjustments when
used for a different part number. Also, after loading, it is recommended to edit each step and
check settings.
DDR Test suite testing and tuning features are available from the Tools view.
The DDR suite relies on two important concepts:
• the DDR timings as key inputs for the configuration of the DDR Controller and PHY
• the tuning of DDR signals to compensate board design imperfections.
Another example: for a configuration with two “DDR3 16 bits 2 Gb” chips, settings are
“DDR3/DDR3L”, “32 bits” and 4 Gb”.
Note: Contexts for DDR IP cannot be changed, DDR is tied to “Cortex-A7 Non-Secure” identified
as “Cortex-A7 NS” in the tool.
DDR configuration
Clicking on a parameter will show additional details in the DDR configuration footer.
• The DDR frequency is taken from the ‘Clock configuration’ tab, it cannot be changed in
the DDR configuration.
• The ‘Relaxed Timing’ mode is used during bring-up phase for trying relaxed key DDR
timings value (one tCK added to tRC, tRCD and tRP timings)
• Other parameters must be retrieved from the user DDR datasheet.
• Some parameters are read-only: they are for information only and depend on the DDR
type.
Clicking “generate code” automatically computes the DDR node of the device tree (DDR
Controller and DDR PHY registers values) based on these parameters.
DDR3 configuration
For DDR3, the configuration is made easier with the selection of a Speed Bin / Grade
combination, instead of manually editing timing parameters.
The Speed Bin / Grade combination must match the selected DDR. If the exact combination
is not in the pick-list, “1066E / 6-6-6” must be selected for faster DDR Speed bin / Grade,
whereas “1066G / 8-8-8” can be used as a relaxed configuration.
Timing edition is then optional, and reserved for advanced users: select Show Advanced
parameters to display the list.
Prerequisites
• Installation of ST-Link USB driver to perform firmware upgrades: for Windows, latest
version of STSW-LINK009 must be used. For Linux, the STSW-LINK007 driver must
be used. Both can be downloaded from www.st.com.
• Installation of STM32CubeProgrammer (for SYSRAM loading only): installer can be
downloaded from www.st.com.
If U-Boot SPL loading in SysRAM is required, it can be performed through UART or USB
using the STM32CubeProgrammer tool. If not automatically detected by STM32CubeMX,
the STM32CubeProgrammer tool location must be specified in the Connection settings
window: click to open it. U-Boot SPL file must be manually selected in the build image
folder.
Once up, the connection gives the various services and target information (see Figure 271).
Output/Log messages
STM32CubeMX outputs DDR suite related activity logs (see Figure 272) and interactive
protocol communication logs (see Figure 273). They are displayed by enabling outputs from
the Window menu.
This step is optional if the used U-Boot SPL already contains the required DDR
configuration. It trigs the DDR Controller and PHY initialization with those registers, and
allows the user to quickly test a configuration without generating the device tree and
dedicated U-Boot SPL binary file.
In case of duplicate labels, a unique suffix, consisting of the pin port letter and the
pin index number, is added and used for the generation of the associated define
statements.
In the example of a duplicate I2C1 labels shown in Figure 280, the code
generation produces the following code, keeping the I2C1 label on the original port
B pin 6 define statements and adding B7 suffix on pin 7 define statements:
In order for the generated project to compile, define statements shall follow strict
naming conventions. They shall start with a letter or an underscore as well as the
corresponding label. In addition, they shall not include any special character such
as minus sign, parenthesis or brackets. Any special character within the label will
be automatically replaced by an underscore in the define name.
If the label contains character strings between “[]” or “()”, only the first string listed
is used for the define name. As an example, the label “LD6 [Blue Led]”
corresponds the following define statements:
#define LD6_Pin GPIO_PIN_15
#define LD6_GPIO_Port GPIOD
The define statements are used to configure the GPIOs in the generated
initialization code. In the following example, the initialization of the pins labeled
Audio_RST_Pin and LD4_Pin is done using the corresponding define statements:
/*Configure GPIO pins : LD4_Pin Audio_RST_Pin */
GPIO_InitStruct.Pin = LD4_Pin | Audio_RST_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_LOW;
HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);
4. Finally it generates a Projects folder that contains the toolchain specific files that match
the user project settings. Double-clicking the IDE specific project file launches the IDE
and loads the project ready to be edited, built and debugged.
Table 20. LL versus HAL code generation: drivers included in STM32CubeMX projects
Project configuration and Mix of HAL
HAL only LL only Comments
drivers to be included and LL
Table 21. LL versus HAL code generation: STM32CubeMX generated header files
Generated Mix of HAL
HAL only LL only Comments
header files and LL
Table 23. LL versus HAL: STM32CubeMX generated functions and function calls
Generated source
HAL only LL only Mix of HAL and LL Comments
files
Table 23. LL versus HAL: STM32CubeMX generated functions and function calls (continued)
Generated source
HAL only LL only Mix of HAL and LL Comments
files
Figure 286. Project root folder with corresponding custom generated files
Define= USE_STM32F429I_DISCO
– Enabling HAL modules in generated stm32f4xx_hal_conf.h
HAL modules can be enabled using the following syntax after the [Others] line:
Syntax
HALModule = <ModuleName1>; <ModuleName1>;
Example
HALModule=I2S;I2C
[Groups]
Drivers/BSP/STM32F429IDISCO=C:\Users\frq09031\STM32Cube\Repository\STM3
2Cube_FW_F4_V1.14.0\Drivers\BSP\STM32F429I-
Discovery\stm32f429i_discovery.c;
C:\Users\frq09031\STM32Cube\Repository\STM32Cube_FW_F4_V1.14.0\Drivers\
BSP\STM32F429I-Discovery\stm32f429i_discovery.h
Lib=C:\Users\frq09031\STM32Cube\Repository\STM32Cube_FW_F4_V1.14.0\
Middlewares\Third_Party\FreeRTOS\Source\portable\IAR\ARM_CM4F\portasm.s
Doc=$PROJ_DIR$\..\readme.txt
[Others]
Define = USE_ STM32F429I_DISCO
HALModule = UART;SPI
Upon project generation, the presence of this .extSettings file triggers the update of:
• the project MyF429IDiscoProject.ewp file in EWARM folder (see Figure 289)
• the stm32f4xx_hal_conf.h file in the project Inc folder (see Figure 290)
• the project view within EWARM user interface as shown in Figure 291 and Figure 292.
Figure 291. New groups and new files added to groups in EWARM IDE
For working with Arm Cortex-M dual-core products, STM32CubeMX generates code for
both cores automatically according to the context assignment and initializer choices made in
the user interface (see Section 4.6: Pinout & Configuration view for STM32H7 dual-core
product lines for details).
Figure 294. Startup and linker files for STM32H7 dual-core devices
In STM32CubeMX project manager view, all project generation options remain available.
However, the choice of toolchains is limited to the IDEs/compilers supporting the
Cortex®-M33 core:
• EWARM v8.32 or higher
• MDK-ARM v5.27 or higher (ARM compiler 6)
• STM32CubeIDE (GCC v4.2 or higher)
Upon product selection, STM32CubeMX requires to choose between enabling TrustZone®
or not.
• When TrustZone® is enabled, STM32CubeMX generates two C projects: one secured
and one non-secured. After compilation, two images are available for download, one
for each context.
• When TrustZone® is disabled, STM32CubeMX generates a non-secured C project, as
for other products not supporting it.
Specificities
When TrustZone® is enabled, the project generation must be adjusted to ensure that secure
and non-secure images can be built.
Figure 295. Building secure and non-secure images with ARMv8-M TrustZone®
When TrustZone® is enabled for the project, STM32CubeMX generates three folders:
• NonSecure for non-secure code
• Secure for secure code
• Secure_nsclib for non-secure callable region
See Figure 296 (use TZ_BasicStructure_project_inCubeIDE.png) and Figure 297 (use
STM32L5_STM32CubeMX_Project_settings_inCubeIDE.png).
Figure 296. Project explorer view for STM32L5 TrustZone® enabled projects
The Device tree in Linux is used to provide a way to describe non-discoverable hardware.
STMicroelectronics is widely using the device tree for all the platform configuration data,
including DDR configuration.
Linux developers can manually edit device tree source files (dts), but as an alternative
STM32CubeMX offers a partial device-tree generation service to reduce effort and to ease
new comers. STM32CubeMX intends to generate partially device trees corresponding to
board level configuration. Partial means that the entire (board level) device-trees are not
generated, but only main sections that usually imply huge efforts and can cause compilation
errors and dysfunction:
• folders structure and files to folders distribution
• dtsi and headers inclusions
• pinCtrl and clocks generation
• System-On-Chip device nodes positioning
• multi-core related configurations (Etzpc binding, resources manager binding,
peripherals assignment)
For more details refer to “Device Tree for Dummies” from Thomas Petazzoni, available on
https://elinux.org.
For more information about STM32MP1 series device tree specificities, refer to ST Wiki
https://wiki.st.com/stm32mpu.
The DT generation path can be configured from the Project Manager view, in the Advanced
Settings tab, under OpenSTLinux Settings (see Figure 301). For each Device tree
STM32CubeMX generates Device tree source (DTS) files.
This section describes the configuration and C code generation process. It takes as an
example a simple LED toggling application running on the STM32F4DISCOVERY board.
STM32CubeMX views are then populated with the selected MCU database (Figure 306).
Optionally, remove the MCUs Selection bottom window by deselecting Window> Outputs
submenu (see Figure 307).
b) Enable a timer to be used as timebase for toggling the LED. This is done by
selecting Internal Clock as TIM3 clock source from the peripheral tree (see
Figure 309).
c) You can also configure the RCC to use an external oscillator as potential clock
source (see Figure 310).
Answering No will require to provide a name and location for the report only.
As shown in Figure 313, a confirmation message is displayed when the operation is
successful.
2. Open the .pdf report using Adobe Reader or the .txt report using your favorite text
editor. The reports summarize all the settings and MCU configuration performed for the
project.
2. First select the clock source (HSE, HSI or PLLCLK) that will drive the system clock of
the microcontroller.
In the example taken for the tutorial, select HSI to use the internal 16 MHz clock (see
Figure 315).
To use an external clock source (HSE or LSE), the RCC peripheral shall be configured
in the Pinout view since pins will be used to connect the external clock crystals (see
Figure 316).
– Select the external PLL clock source and the HSI or HSE as the PLL input clock
source.
3. Keep the core and peripheral clocks to 16 MHz using HSI, no PLL and no prescaling.
Note: Optionally, further adjust the system and peripheral clocks using PLL, prescalers and
multipliers:
Other clock sources independent from the system clock can be configured as follows:
– USB OTG FS, Random Number Generator and SDIO clocks are driven by an
independent output of the PLL.
– I2S peripherals come with their own internal clock (PLLI2S), alternatively derived
by an independent external clock source.
– USB OTG HS and Ethernet Clocks are derived from an external source.
4. Optionally, configure the prescaler for the Microcontroller Clock Output (MCO) pins that
allow to output two clocks to the external circuit.
5. Click to save the project.
6. Go to the Configuration tab to proceed with the project configuration.
b) with a 16 MHz APB clock (Clock tree view), set the prescaler to 16000 and the
counter period to 1000 to make the LED blink every millisecond.
4. Select the Configuration view. FatFs and USB buttons are then displayed.
5. FatFs and USB using default settings are already marked as configured . Click
FatFs and USB buttons to display default configuration settings. You can also change
them by following the guidelines provided at the bottom of the window.
3. Select the Code Generator tab to choose various C code generation options:
– The library files copied to Projects folder.
– C code regeneration (e.g. what is kept or backed up during C code regeneration).
– HAL specific action (e.g. set all free pins as analog I/Os to reduce MCU power
consumption).
In the tutorial example, select the settings as displayed in Figure 333 and click OK.
Note: A dialog window appears when the firmware package is missing. Go to next section for
explanation on how to download the firmware package.
To solve this issue, execute the next two steps. Skip them otherwise.
3. Select Help > Updater settings menu and adjust the connection parameters to match
your network configuration.
4. Click Check connection. The check mark turns green once the connection is
established.
6. Finally, a confirmation message is displayed to indicate that the C code generation has
been successful.
7. Click Open Folder to display the generated project contents or click Open Project to
open the project directly in your IDE. Then proceed with Section 11.8.
2. As an example, select .eww file to load the project in the IAR™ EWARM IDE.
The htim3 structure handler, system clock, GPIO and TIM3 initialization functions are
defined. The initialization functions are called in the main.c. For now the user C code
sections are empty.
4. In the IAR™ IDE, right-click the project name and select Options.
5. Click the ST-LINK category and make sure SWD is selected to communicate with the
STM32F4DISCOVERY board. Click OK.
6. Select Project > Rebuild all. Check if the project building has succeeded.
This C code implements the weak callback function defined in the HAL timer driver
(stm32f4xx_hal_tim.h) to toggle the GPIO pin driving the green LED when the
timer counter period has elapsed.
8. Rebuild and program your board using . Make sure the SWD ST-LINK option is
checked as a Project options otherwise board programming will fail.
9. Launch the program using . The green LED on the STM32F4DISCOVERY board
will blink every second.
10. To change the MCU configuration, go back to STM32CubeMX user interface,
implement the changes and regenerate the C code. The project will be updated,
preserving the C code in the user sections if option in
Project Manager’s Code Generator tab is enabled.
The tutorial consists in creating and writing to a file on the STM32429I-EVAL1 SD card using
the FatFs file system middleware.
To generate a project and run tutorial 2, follow the sequence below:
1. Launch STM32CubeMX.
2. Select File > New Project. The Project window opens.
3. Click the Board Selector Tab to display the list of ST boards.
4. Select EvalBoard as type of Board and STM32F4 as Series to filter down the list.
5. Answer Yes to Initialize all peripherals with their default mode so that the code is
generated only for the peripherals used by the application.
6. Select the STM32429I-EVAL board and click OK. Answer No in the dialog box asking
to initialize all peripherals to their default modes (see Figure 351). The Pinout view is
loaded, matching the MCU pinout configuration on the evaluation board (see
Figure 352).
7. From the Peripheral tree on the left, expand the SDIO peripheral and select “SD 4 bits
wide bus” (see Figure 353). In the configuration panel, from the DMA settings tab, add
SDIO_RX and SDIO_TX DMA requests.
8. Finally, go pack to the peripheral tree panel, select NVIC and enable the SDIO global
interrupt from the configuration panel.
9. Under the Middlewares category, check SD card as FatFs mode (see Figure 354).
From the Pinout view on the right, enable, as GPIO input, a pin to be used for the SDIO
detection.
In the configuration panel below the mode panel, go to the platform settings tab and
configure the SD_detection using the pin previously enabled.
Finally, go to FatFs "Advanced settings tab" and enable "Use DMA template".
10. Configure the clocks as follows:
a) Select the RCC peripheral from the Pinout view (see Figure 355).
b) Configure the clock tree from the clock tab (see Figure 356).
11. In the Project tab, specify the project name and destination folder. Then, select the
EWARM IDE toolchain.
Note that project heap and stack size can be adjusted to the minimum required for the
FATFS application.
12. Click Ok. Then, on the toolbar menu, click to generate the project.
13. Upon code generation completion, click Open Project in the Code Generation dialog
window (see Figure 358). This opens the project directly in the IDE.
14. In the IDE, check that heap and stack sizes are sufficient: right click the project name
and select Options, then select Linker. Check Override default to use the icf file from
STM32CubeMX generated project folder. if not already done through CubeMX User
interface (under Linker Settings from Project Manager's project tab), adjust the heap
and stack sizes (see Figure 359).
Note: When using the MDK-Arm toolchain, go to the Application/MDK-ARM folder and
double- click the startup_xx.s file to edit and adjust the heap and stack sizes there.
15. Go to the Application/User folder. Double-click the main.c file and edit it.
16. The tutorial consists in creating and writing to a file on the evaluation board SD card
using the FatFs file system middleware:
a) At startup all LEDs are OFF.
b) The red LED is turned ON to indicate that an error occurred (e.g. FatFs
initialization, file read/write access errors).
c) The orange LED is turned ON to indicate that the FatFs link has been successfully
mounted on the SD driver.
d) The blue LED is turned ON to indicate that the file has been successfully written to
the SD card.
e) The green LED is turned ON to indicate that the file has been successfully read
from file the SD card.
17. For use case implementation, update main.c with the following code:
a) Insert main.c private variables in a dedicated user code section:
/* MCU Configuration----------------------------------------*/
if(retSD == 0){
/* success: set the orange LED on */
HAL_GPIO_WritePin(GPIOG, GPIO_PIN_7, GPIO_PIN_RESET);
/*##-2- Register the file system object to the FatFs module ###*/
if(f_mount(&SDFatFs, (TCHAR const*)SDPath, 0) != FR_OK){
/* FatFs Initialization Error : set the red LED on */
HAL_GPIO_WritePin(GPIOG, GPIO_PIN_10, GPIO_PIN_RESET);
while(1);
} else {
/*##-3- Create a FAT file system (format) on the logical drive#*/
/* WARNING: Formatting the uSD card will delete all content on the
device */
if(f_mkfs((TCHAR const*)SDPath, FM_ANY, 0, buffer, sizeof(buffer))
!= FR_OK){
/* FatFs Format Error : set the red LED on */
HAL_GPIO_WritePin(GPIOG, GPIO_PIN_10, GPIO_PIN_RESET);
while(1);
} else {
/*##-4- Create & Open a new text file object with write access#*/
if(f_open(&MyFile, "Hello.txt", FA_CREATE_ALWAYS | FA_WRITE) !=
FR_OK){
/* 'Hello.txt' file Open for write Error : set the red LED on */
HAL_GPIO_WritePin(GPIOG, GPIO_PIN_10, GPIO_PIN_RESET);
while(1);
} else {
/*##-5- Write data to the text file ####################*/
res = f_write(&MyFile, wtext, sizeof(wtext), (void
*)&byteswritten);
if((byteswritten == 0) || (res != FR_OK)){
/* 'Hello.txt' file Write or EOF Error : set the red LED on */
HAL_GPIO_WritePin(GPIOG, GPIO_PIN_10, GPIO_PIN_RESET);
while(1);
} else {
/*##-6- Successful open/write : set the blue LED on */
HAL_GPIO_WritePin(GPIOG, GPIO_PIN_12, GPIO_PIN_RESET);
f_close(&MyFile);
/*##-7- Open the text file object with read access #*/
if(f_open(&MyFile, "Hello.txt", FA_READ) != FR_OK){
/* 'Hello.txt' file Open for read Error : set the red LED on */
HAL_GPIO_WritePin(GPIOG, GPIO_PIN_10, GPIO_PIN_RESET);
while(1);
} else {
/*##-8- Read data from the text file #########*/
res = f_read(&MyFile, rtext, sizeof(wtext), &bytesread);
if((byteswritten == 0)|| (res != FR_OK)){
/* 'Hello.txt' file Read or EOF Error : set the red LED on */
HAL_GPIO_WritePin(GPIOG, GPIO_PIN_10, GPIO_PIN_RESET);
while(1);
} else {
/* Successful read : set the green LED On */
HAL_GPIO_WritePin(GPIOG, GPIO_PIN_6, GPIO_PIN_RESET);
/* Infinite loop */
/* USER CODE BEGIN WHILE */
while (1)
5. Enable the Transition checker to ensure the sequence is valid (see Figure 361). This
option allows verifying that the sequence respects the allowed transitions implemented
within the STM32L476RG.
6. Click the Add button to add steps that match the sequence described in Figure 361.
– By default the steps last 1 ms each, except for the wake-up transitions preset
using the transition times specified in the product datasheet (see Figure 362).
– Some peripherals for which consumption is unavailable or negligible are
highlighted with ‘*’ (see Figure 362).
Step 1 (Run)
• Findings
All peripherals are enabled although the application requires only the RTC.
• Actions
– Lower the operating frequency
– Enable only the RTC peripheral
– To reduce the average current consumption, reduce the time spent in this mode
• Results
The current is reduced from 9.05 to 2.16 mA (see Figure 364).
See Figure 370 for the overall results: 7 ms duration, about two months battery life, and an
average current consumption of 165.25 µA.
Use the compare button to compare the current results to the original ones saved as
SequenceOne.pcs.
This tutorial aims at demonstrating how to use STM32CubeMX to create a UART serial
communication application for a NUCLEO-L053R8 board.
A Windows PC is required for the example. The ST-Link USB connector is used both for
serial data communications, and firmware downloading and debugging on the MCU. A
Type-A to mini-B USB cable must be connected between the board and the computer. The
USART2 peripheral uses PA2 and PA3 pins, which are wired to the ST-Link connector. In
addition, USART2 is selected to communicate with the PC via the ST-Link Virtual COM Port.
A serial communication client, such as Tera Term, needs to be installed on the PC to display
the messages received from the board over the virtual communication Port.
2. Select Internal Clock as clock source under TIM2 peripheral (see Figure 373).
3. Select the Asynchronous mode for the USART2 peripheral (see Figure 374).
4. Check that the signals are properly assigned on pins (see Figure 375):
– SYS_SWDIO on PA13
– TCK on PA14
– USART_TX on PA2
– USART_RX on PA3
14.4 Configuring the MCU clock tree from the Clock Configuration
view
1. Go to the Clock Configuration tab and leave the configuration untouched, in order to
use the MSI as input clock and an HCLK of 2.097 MHz (see Figure 376).
3. Click TIM2 and change the prescaler to 16000, the Word Length to 8 bits and the
Counter Period to 1000 (see Figure 378).
4. Enable TIM2 global interrupt from the NVIC Settings tab (see Figure 379).
If the firmware package version is not already available on the user PC, a progress
window opens to show the firmware package download progress.
2. To configure Tera Term to listen to the relevant virtual communication port, adjust the
parameters to match the USART2 parameter configuration on the MCU (see
Figure 383).
3. The Tera Term window displays a message coming from the board at a period of a few
seconds (see Figure 384).
When List pinout compatible MCUs is selected from the Pinout menu, STM32CubeMX
retrieves the list of the MCUs which are compatible with the current project configuration,
and offers to export the current configuration to the newly selected compatible MCU.
This tutorial shows how to display the list of compatible MCUs and export your current
project configuration to a compatible MCU:
1. Load an existing project, or create and save a new project:
2. Go to the Pinout menu and select List Pinout Compatible MCUs. The Pinout
compatible window pops up (see Figure 386 and Figure 387).
If needed, modify the search criteria and the filter options and restart the search
process by clicking the Search button.
The color shading and the Comments column indicate the level of matching:
– Exact match: the MCU is fully compatible with the current project (see Figure 387
for an example).
– Partial match with hardware compatibility: the hardware compatibility can be
ensured but some pin names could not be preserved. Hover the mouse over the
desired MCU to display an explanatory tooltip (see Figure 386 for an example).
– Partial match without hardware compatibility: not all signals can be assigned to the
exact same pin location and a remapping will be required. Hover the mouse over
the desired MCU to display an explanatory tooltip (see Figure 387 for an
example).
Figure 387. List of Pinout compatible MCUs - Exact and partial match
3. Then, select an MCU to import the current configuration to, and click OK, Import:
4. To see the list of compatible MCUs at any time, select Outputs under the Window
menu.
To load the current configuration to another compatible MCU, double-click the list of
compatible MCUs.
5. To remove some constraints on the search criteria, several solutions are possible:
– Select the Ignore Pinning Status checkbox to ignore pin status (locked pins).
– Select the Ignore Power Pins checkbox not to take into account the power pins.
– Select the Ignore System Pins not take into account the system pins. Hover the
mouse over the checkbox to display a tooltip that lists the system pins available on
the current MCU.
Figure 390. Additional software components enabled for the current project
The pack name highlighted in green indicates that all conditions for the selected
software components resolve to true. If at least one condition is not resolved, the pack
name is highlighted in orange.
7. Select the Project manager project tab to specify project parameters (see Figure 392),
and choose IAR™ EWARM as IDE.
This tutorial demonstrates how to achieve a functional project using the X-Cube-BLE1
software pack.
Below the prerequisites to run this tutorial:
• Hardware: NUCLEO-L053R8, X-NUCLEO-IDB05A1 and mini-USB cable (see
Figure 394)
• Tools: STM32CubeMX, IDE (Atollic® or any other toolchain supported by
STM32CubeMX)
• Embedded software package: STM32CubeL0 (version 1.10.0 or higher), X-Cube-BLE1
1.1.0 (see Figure 395).
• Mobile application (see Figure 396): STMicroelectronics BlueNRG application for iOS®
or Android™
c) Click OK to apply the selection to the project and close the window. The left panel
Additional Software section is updated accordingly.
5. Enable peripherals and GPIOs from the Pinout tab (see Figure 401):
a) Configure USART2 in Asynchronous mode.
b) Configure SPI1 in Full-duplex master mode.
c) Left-click the following pins and configure them for the required GPIO settings:
PA0: GPIO_EXTI0
PA1: GPIO_Output
PA8: GPIO_Output
d) Enable Debug Serial Wire under SYS peripheral.
Check that the icon turns to . Click OK to close the Configuration window.
The “Main project” contains the “SoC and IPs configuration” at initialization time and a
runtime description of the main application. STM32CubeMX allows to describe the “SOC
and IPs Configuration” part.
Each LPBAM application contains a “SoC and IPs configuration” and a runtime description.
STM32CubeMX allows to describe both.
STM32CubeMX generated code for “SoC and IPs configurations” uses the STM32Cube
HAL and/or LL APIs, for both the main project and the LPBAM application. The code
generated for the LPBAM application runtime uses the LPBAM firmware API.
Figure 407 is an example of what can be executed at runtime for a simple LPBAM project
composed of the main application and of one LPBAM application.
To rename an application (or a queue), right-click the application (or the queue) name and
select “Rename”. Note that the application name is used in the generated project.
To switch between LPBAM applications, click the application name, this loads the LPBAM
panel for the selected application.
To switch between queues in an LPBAM application, click the queue name: the middle and
right panels are refreshed to display the selected queue and its configuration.
Note: LPBAM applications use the LPBAM firmware APIs and consist of chained DMA transfers.
All IPs used at runtime by the LPBAM must be configured in the Pinout & Configuration
view. Their configuration must be coherent with the LPBAM scenario.
Clicking “Check LPBAM Design” on the upper right corner of the user interface returns, for
each IP used but not configured in an LPBAM application, a warning in the LPBAM output
window.
Warning: “Check LPBAM Design” checks only that the IPs are
configured in the “Pinout & Configuration”, it does not check
whether the HAL configuration is coherent with the LPBAM
APIs used in the scenario.
Some functions first configure the IP, then manage the data transfer. In case of circular
mode, the loop can be plugged on the configuration (“Conf”) or on the data part (“Data”) of
the function.
An example is provided in Figure 419: when the queue is executed, the two first nodes and
the configuration of the third node are executed once. whereas the data transfer is repeated
as part of the loop.
18.3.8 Queue description: configuring the DMA channel hosting the queue
The execution of an LPBAM queue consists of LPDMA chained transfers. The DMA hosting
the queue execution must be configured as needed by the application (see Figure 420).
Basic configuration
Select the queue to be configured by clicking the queue name on the center panel, the
configuration of the DMA channel hosting that queue is shown in the right panel.
Note that some settings usually available for configuring a DMA channel are not provided in
the user interface, as they are directly managed either by STM32CubeMX or by the LPBAM
driver.
When a parameter is set to a hardware resource such as a GPIO, the resource must be
configured in the Pinout & Configuration view.
In the example shown in Figure 422, the COMP “Input Plus” is set to PC5. If PC5 is not
configured in the “Pinout & configuration” view, the generated LPBAM application can gets a
“null signal” on Input Plus, and will be not functional.
To fix this issue:
• Go to the Pinout&Configuration view
• Search PC5 using the search field
• Right-click the PC5 pin and select COMP_Inp (see Figure 423)
Another example can be made using a timer to generate a PWM signal. The HAL driver
requires a timer channel to be configured as output. Same applies when using the LPBAM
firmware.
Note: All constraints concerning the initial configuration of the IP are mentioned in the LPBAM
firmware documentation. Use STM32CubeMX “LPBAM Design check” mechanism (see
dedicated section) to detect missing configurations.
Taking the COMP function “Start” as an example (see Figure 424), choose the function
execution to be triggered on the rising edge of hardware signal, for the example, then, select
the hardware signal among the list of hardware signals proposed.
DMA settings can be changed, but they depend upon the IP and the function.
For example, for “COMP Output Level”:
• Data transferred are output data and are transferred from the register IP to the memory.
The “Source Address” referring to the IP data register is not incremented:
STM32CubeMX user interface shows that the “Source address increment after
transfer” parameter cannot be enabled.
• Data transferred to memory can be saved at the same memory address, or in a Table:
in this case, the “Destination Address increment after transfer” can be disabled or left
enabled (see Figure 426).
Figure 427. Reconfiguring DMA for data transfer when destination is memory
STM32CubeMX generates:
• In the Core/Inc folder, the stm32_lpbam_conf.h file that defines all the LPBAM modules
enabled for the LPBAM applications, to be used by the LPBAM utility firmware.
• In the LPBAM folder, the code for the LPBAM applications and their scenarios. The
lpbam_<application name>.h file provides the prototypes of the functions to call in the
main project to initialize the application, build and initialize the scenario, link it with the
DMA, start it, stop it, unlink it, and de-initialize it.
As an example, for the LpbamAp1 application, STM32CubeMX generates the following
functions:
/* LpbamAp1 application initialization */
void MX_LpbamAp1_Init(void);
19 FAQ
19.7 Why does the RTC multiplexer remain inactive on the Clock
tree view?
To enable the RTC multiplexer the user must enable the RTC peripheral in the Pinout view
as indicated below.
19.8 How can I select LSE and HSE as clock source and
change the frequency?
The LSE and HSE clocks become active once the RCC is configured as such in the Pinout
view. See Figure 437 for an example. The clock source frequency can then be edited and
the external source selected, see Figure 438.
For STM32CubeMX to find an alternative solution for the I2C peripheral mode, the user will
need to unpin I2C1 pins and select the I2C1 mode from the peripheral tree view (see
Figure 441 and Figure 442).
Figure 445. One block = one peripheral mode - I2C1_SMBA function assigned to PB5
Example
STM32CubeMX remaps USART3 hardware-flow-control mode to the (PD8-PD9-PD11-
PD12) block, because PB14 of USART3 default block is already allocated to the
SPI2_MISO function (see Figure 446).
Example
With the Keep current signal placement enabled, if USART3 synchronous mode is set first,
the Asynchronous default block (PB10-PB11) is mapped and Ethernet becomes unavailable
(shown in red) (see Figure 448).
Unchecking allows STM32CubeMX shifting blocks around
and freeing a block for the Ethernet MII mode. (see Figure 449).
hi2s2.Init.AudioFreq = I2S_AUDIOFREQ_192K;
hi2s2.Init.CPOL = I2S_CPOL_LOW;
hi2s2.Init.ClockSource = I2S_CLOCK_PLL;
hi2s2.Init.FullDuplexMode = I2S_FULLDUPLEXMODE_ENABLE;
HAL_I2S_Init(&hi2s2);
}
By default, the peripheral initialization is done in main.c. If the peripheral is used by a
middleware mode, the peripheral initialization can be done in the middleware corresponding
.c file.
Customized HAL_<Peripheral Name>_MspInit() functions are created in the
stm32f4xx_hal_msp.c file to configure the low-level hardware (GPIO, CLOCK) for the
selected peripherals.
B.3.1 Overview
STM32CubeMX does not support C user code insertion in Middleware stack native files
although stacks such as LwIP might require it in some use cases.
STM32CubeMX generates middleware Init functions that can be easily identified thanks to
the MX_ prefix:
MX_LWIP_Init(); // defined in lwip.h file
MX_USB_HOST_Init(); // defined in usb_host.h file
MX_FATFS_Init(); // defined in fatfs.h file
Note however the following exceptions:
• No Init function is generated for FreeRTOS unless the user chooses, from the Project
settings window, to generate Init functions as pairs of .c/.h files. Instead, a
StartDefaultTask function is defined in the main.c file and CMSIS-RTOS native function
(osKernelStart) is called in the main function.
• If FreeRTOS is enabled, the Init functions for the other middlewares in use are called
from the StartDefaultTask function in the main.c file.
Example:
void StartDefaultTask(void const * argument)
{
/* init code for FATFS */
MX_FATFS_Init();
/* init code for LWIP */
MX_LWIP_Init();
/* init code for USB_HOST */
MX_USB_HOST_Init();
/* USER CODE BEGIN 5 */
/* Infinite loop */
for(;;)
{
osDelay(1);
}
/* USER CODE END 5 */
}
B.3.4 FatFs
FatFs is a generic FAT/exFAT file system solution well suited for small embedded systems.
FatFs configuration is available in ffconf.h generated file.
The initialization of the SDIO peripheral for the FatFs SD card mode and of the FMC
peripheral for the FatFs External SDRAM and External SRAM modes are kept in the main.c
file.
Some files need to be modified by the user to match user board specificities (BSP in
STM32Cube embedded software package can be used as example):
• bsp_driver_sd.c/.h generated files when using FatFs SD card mode
• bsp_driver_sram.c/.h generated files when using FatFs External SRAM mode
• bsp_driver_sdram.c/.h generated files when using FatFs External SDRAM mode.
Multi-drive FatFs is supported, which means that multiple logical drives can be used by the
application (External SDRAM, External SRAM, SD card, USB disk, User defined). However
support of multiple instances of a given logical drive is not available (e.g. FatFs using two
instances of USB hosts or several RAM disks).
NOR and NAND flash memory are not supported. In this case, the user shall select the
FatFs user-defined mode and update the user_diskio.c driver file generated to implement
the interface between the middleware and the selected peripheral.
B.3.5 FreeRTOS
FreeRTOS is a free real-time embedded operating system well suited for microcontrollers.
FreeRTOS configuration is available in FreeRTOSConfig.h generated file.
When FreeRTOS is enabled, all other selected middleware modes (e.g., LwIP, FatFs, USB)
will be initialized within the same FreeRTOS thread in the main.c file.
When GENERATE_RUN_TIME_STATS, CHECK_FOR_STACK_OVERFLOW,
USE_IDLE_HOOK, USE_TICK_HOOK and USE_MALLOC_FAILED_HOOK parameters
are activated, STM32CubeMX generates freertos.c file with empty functions that the user
shall implement. This is highlighted by the tooltip (see Figure 450).
B.3.6 LwIP
LwIP is a small independent implementation of the TCP/IP protocol suite: its reduced RAM
usage makes it suitable for use in embedded systems with tens of Kbytes of free RAM.
LwIP initialization function is defined in lwip.c, while LwIP configuration is available in
lwipopts.h generated file.
STM32CubeMX supports LwIP over Ethernet only. The Ethernet peripheral initialization is
done within the middleware initialization C code.
STM32CubeMX does not support user C code insertion in stack native files. However, some
LwIP use cases require modifying stack native files (e.g., cc.h, mib2.c): user modifications
shall be backed up since they will be lost at next STM32CubeMX generation.
Starting with LwIP release 1.5, STM32CubeMX LwIP supports IPv6 (see Figure 452).
DHCP must be disabled, to configure a static IP address.
STM32CubeMX generated C code will report compilation errors when specific parameters
are enabled (disabled by default). The user must fix the issues with a stack patch
(downloaded from Internet) or user C code. The following parameters generate an error:
• MEM_USE_POOLS: user C code to be added either in lwipopts.h or in cc.h (stack file).
• PPP_SUPPORT, PPPOE_SUPPORT: user C code required
• MEMP_SEPARATE_POOLS with MEMP_OVERFLOW_CHECK > 0: a stack patch
required
• MEM_LIBC_MALLOC & RTOS enabled: stack patch required
• LWIP_EVENT_API: stack patch required
In STM32CubeMX, the user must enable FreeRTOS in order to use LwIP with the netconn
and sockets APIs. These APIs require the use of threads and consequently of an operating
system. Without FreeRTOS, only the LwIP event-driven raw API can be used.
B.3.7 Libjpeg
Libjpeg is a widely used C-library that allows reading and writing JPEG files. It is delivered
within STM32CubeF7, STM32CubeH7, STM32CubeF2 and STM32CubeF4 embedded
software packages.
STM32CubeMX generates the following files, whose content can be configured by the user
through STM32CubeMX user interface:
• libjpeg.c/.h
The MX_LIBJPEG_Init() initialization function is generated within the libjpeg.c file. It is
empty. It is up to the user to enter in the user sections the code and the calls to the
libjpeg functions required for the application.
• jdata_conf.c
This file is generated only when FatFs is selected as data stream management type.
• jdata_conf.h
The content of this file is adjusted according to the datastream management type
selected.
• jconfig.h
This file is generated by STM32CubeMX. but cannot be configured.
• jmorecfg.h
Some but not all the define statements contained in this file can be modified through
the STM32CubeMX libjpeg configuration menu.
STM32CubeMX generates the following files, whose contents can be modified by the user
through STM32CubeMX user interface (see Figure 456: Mbed TLS configuration window)
and/or using user sections in the code itself:
• mbedtls_config.h
• mbedtls.h
• net_sockets.c (generated only if LwIP is enabled)
• mbedtls.c
B.3.9 TouchSensing
The STM32 TouchSensing library is a C-library that allows the creation of higher-end human
interfaces by replacing conventional electromechanical switches by capacitive sensors with
STM32 microcontrollers.
It requires the touch-sensing peripheral to be configured on the microcontroller.
STM32CubeMX generates the following files, whose contents can be modified by the user
through STM32CubeMX user interface (see Figure 457: Enabling the TouchSensing
peripheral, Figure 458: Touch-sensing sensor selection panel and Figure 459:
TouchSensing configuration panel) and/or using user sections in the code itself:
• touchsensing.c/.h
• tsl_user.c/.h
• tsl_conf.h
B.3.10 PDM2PCM
The PDM2PCM library is a C-library that allows converting a pulse density modulated
(PDM) data output into a 16-bit pulse-code modulation (PCM) format. It requires the CRC
peripheral to be enabled.
STM32CubeMX generates the following files, whose content can be modified by the user
through STM32CubeMX user interface and/or using user sections in the code itself:
• pdm2pcm.h/.c
They are exclusive in a given project and configuration with FreeRTOS is not yet supported.
Application projects generated with STM32CubeMX can be found in the project folder of the
STM32CubeWB MCU package.
This package can be installed through STM32CubeMX following the standard procedure
described in Section 3.4.3: Installing STM32 MCU packages.
BLE configuration
To enable BLE some peripherals (RTC, HSEM, RF) must be activated first.
Then, an application type must be selected, it can be one among Transparent mode, Server
profile, Router profile or Client profile.
Finally, the mode and other parameters relevant to this application type must be configured.
Note: The BLE Transparent mode and all Thread applications require either the USART or the
LPUART peripheral to be configured as well.
Thread configuration
To enable Thread some peripherals (RTC, HSEM, RF) must be activated first.
Then, an application type must be selected and the relevant parameters configured.
STM32 microcontroller part numbers are codified following the below naming conventions:
• Device subfamilies
The higher the number, the more features available.
For example STM32L0 line includes STM32L051, L052, L053, L061, L062, L063
subfamilies where STM32L06x part numbers come with AES while STM32L05x do not.
The last digit indicates the level of features. In the above example:
– 1 = Access line
– 2 = with USB
– 3 = with USB and LCD.
• Pin counts
– F = 20 pins
– G = 28 pins
– K = 32 pins
– T = 36 pins
– S = 44 pins
– C = 48 pins
– R = 64 (or 66) pins)
– M = 80 pins
– O = 90 pins
– V = 100 pins
– Q = 132 pins (e. g. STM32L162QDH6)
– Z = 144 pins
– I = 176 (+25) pins
– B = 208 pins (e. g. STM32F429BIT6)
– N = 216 pins
• Flash memory sizes
– 4 = 16 Kbytes of flash memory
– 6 = 32 Kbytes of flash memory
– 8 = 64 Kbytes of flash memory
– B = 128 Kbytes of flash memory
– C = 256 Kbytes of flash memory
– D = 384 Kbytes of flash memory
– E = 512 Kbytes of flash memory
– F = 768 Kbytes of flash memory
– G = 1024 Kbytes of flash memory
– I = 2048 Kbytes of flash memory
• Packages
– B = SDIP
– H = BGA
– M = SO
– P = TSSOP
– T = LQFP
– U = VFQFPN
– Y = WLCSP
Figure 469 shows an example of STM32 microcontroller part numbering scheme.
RAM and register contents are lost except for the registers in the Standby circuitry. The
number of enabled peripherals is even more limited than in Stop mode.
The device exits Standby mode upon reset, rising edge on one of the three WKUP pins,
or if an RTC event occurs (if the RTC is ON).
Note: When exiting Stop or Standby modes to enter the Run mode, STM32L1 MCUs go through a
state where the MSI oscillator is used as clock source. This transition can have a significant
impact on the global power consumption. For this reason, the Power Consumption
Calculator introduces two transition steps: WU_FROM_STOP and WU_FROM_STANDBY.
During these steps, the clock is automatically configured to MSI.
external reset (NRST pin), an IWDG reset, a rising edge on the WKUP pin, or an RTC
alarm/ wake-up/tamper/time stamp event occurs.
• VBAT operation
It allows to significantly reduced power consumption compared to the Standby mode.
This mode is available when the VBAT pin powering the Backup domain is connected to
an optional standby voltage supplied by a battery or by another source. The VBAT
domain is preserved (RTC registers, RTC backup register and backup SRAM) and
RTC and LSE oscillator blocks powered. The main difference compared to the Standby
mode is external interrupts and RTC alarm/events do not exit the device from VBAT
operation. Increasing VDD to reach the minimum threshold does.
is powered off. The PLL, MSI RC, HSE crystal and HSI RC oscillators are also switched
off. The LSE or LSI is still running.
After entering Standby mode, the RAM and register contents are lost except for
registers in the Standby circuitry (wake-up logic, IWDG, RTC, LSI, LSE crystal 32 kHz
oscillator, RCC_CSR register).
The device exits Standby mode in 60 µs when an external reset (NRST pin), an IWDG
reset, a rising edge on one of the three WKUP pins, RTC alarm (Alarm A or Alarm B),
RTC tamper event, RTC timestamp event or RTC wake-up event occurs.
• Standby mode without RTC
This mode is identical to Standby mode with RTC, except that the RTC, LSE and LSI
clocks are stopped.
The device exits Standby mode in 60 µs when an external reset (NRST pin) or a rising
edge on one of the three WKUP pin occurs.
Note: The RTC, the IWDG, and the corresponding clock sources are not stopped automatically by
entering Stop or Standby mode. The LCD is not stopped automatically by entering Stop
mode.
Along with STM32CubeMX C code generator, embedded software packages are part of
STM32Cube initiative (refer to DB2164 databrief): these packages include a low-level
hardware abstraction layer (HAL) that covers the microcontroller hardware, together with an
extensive set of examples running on STMicroelectronics boards (see Figure 470). This set
of components is highly portable across the STM32 series. The packages are fully
compatible with STM32CubeMX generated C code.
Middleware examples
FreeRTOS
Polar SSL Device library STEmWin (FatFs)
driver
RTOS
Middleware level
CMSIS
HAL examples
Revision history
STMicroelectronics NV and its subsidiaries (“ST”) reserve the right to make changes, corrections, enhancements, modifications, and
improvements to ST products and/or to this document at any time without notice. Purchasers should obtain the latest relevant information on
ST products before placing orders. ST products are sold pursuant to ST’s terms and conditions of sale in place at the time of order
acknowledgment.
Purchasers are solely responsible for the choice, selection, and use of ST products and ST assumes no liability for application assistance or
the design of purchasers’ products.
Resale of ST products with provisions different from the information set forth herein shall void any warranty granted by ST for such product.
ST and the ST logo are trademarks of ST. For additional information about ST trademarks, refer to www.st.com/trademarks. All other product
or service names are the property of their respective owners.
Information in this document supersedes and replaces information previously supplied in any prior versions of this document.