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 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
14.4 Configuring the MCU clock tree from the Clock Configuration view . . . . 446
14.5 Configuring the peripheral parameters from the Configuration view . . . 447
14.6 Configuring the project settings and generating the project . . . . . . . . . . 450
14.7 Updating the project with the user application code . . . . . . . . . . . . . . . . 451
14.8 Compiling and running the project . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 452
14.9 Configuring Tera Term software as serial communication
client on the PC . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 452
List of tables
List of figures
Figure 202. Set unused GPIO pins with Keep Current Signals Placement checked . . . . . . . . . . . . . . 204
Figure 203. Set unused GPIO pins with Keep Current Signals Placement unchecked . . . . . . . . . . . . 205
Figure 204. Additional software window . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 206
Figure 205. Component dependency resolution . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 210
Figure 206. Details and Warnings panel . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 212
Figure 207. Selection of additional software components . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 213
Figure 208. Additional software components - Updated tree view. . . . . . . . . . . . . . . . . . . . . . . . . . . . 213
Figure 209. LPBAM window. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 214
Figure 210. CAD Resources view . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 215
Figure 211. CAD Resources not available . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 216
Figure 212. CAD Resources selection for download . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 216
Figure 213. CAD Resources in Tools panel. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 217
Figure 214. CAD Resources for STM32CubeMX project. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 217
Figure 215. Boot path configuration ecosystem. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 218
Figure 216. Boot paths for STM32H57x devices . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 219
Figure 217. Boot paths for STM32H56x devices . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 219
Figure 218. Application boot paths (legacy and ST-iRoT projects) . . . . . . . . . . . . . . . . . . . . . . . . . . . 220
Figure 219. Application boot paths (OEM-iRoT and secure manager projects). . . . . . . . . . . . . . . . . . 220
Figure 220. Application boot path (OEM-uRoT assembled) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 221
Figure 221. Application boot path: ST-iRoT and uRoT secure/nonsecure project. . . . . . . . . . . . . . . . 221
Figure 222. Application boot path:
ST-iRoT and secure/nonsecure user application assembled . . . . . . . . . . . . . . . . . . . . . . 222
Figure 223. Application boot path: ST-iRoT dual figure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 222
Figure 224. Application boot path:
(OEM-iRoT and secure/nonsecure user application assembled) . . . . . . . . . . . . . . . . . . . 222
Figure 225. Select the device or board . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 223
Figure 226. Select the STM32H5 device . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 224
Figure 227. Peripheral initialization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 224
Figure 228. Boot paths for STM32H56x devices . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 225
Figure 229. Activate TrustZone . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 225
Figure 230. Device and peripherals configuration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 226
Figure 231. Configuring the project . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 227
Figure 232. Saving the project . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 227
Figure 233. Boot path selection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 228
Figure 234. Select OEM-iRoT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 228
Figure 235. First boot path stage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 229
Figure 236. Select Secure Application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 229
Figure 237. Last boot path stage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 230
Figure 238. Project provisioning . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 230
Figure 239. Flash size not aligned . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 231
Figure 240. Boot path and debug authentication panel . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 231
Figure 241. Authentication and encryption keys regeneration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 232
Figure 242. Secure image configuration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 232
Figure 243. Nonsecure image configuration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 233
Figure 244. Generate the code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 233
Figure 245. Code is generated . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 234
Figure 246. Secure and nonsecure IDE directories . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 234
Figure 247. IDE post build commands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 235
Figure 248. Trusted Package Creator output directory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 235
Figure 249. Board provisioning . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 236
Figure 250. On-screen instructions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 236
Figure 251. Error message . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 237
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.
– From the Project Settings menu, the user can select the development toolchain
(IDE) for which the C code has to be generated. STM32CubeMX ensures that the
IDE relevant project files are added to the project folder so that the project can be
directly imported as a new project within STM32Cube or third party IDEs (IAR™
EWARM, Keil™ MDK-Arm, KITWARE™ CMake, FSF™ Makefile).
• Power consumption calculation
Starting with the selection of a microcontroller part number and a battery type, the user
can define a sequence of steps representing the application life cycle and parameters
(choice of frequencies, enabled peripherals, step duration). STM32CubeMX Power
Consumption Calculator returns the corresponding power consumption and battery life
estimates.
• Clock tree configuration
STM32CubeMX offers a graphic representation of the clock tree as it can be found in
the device reference manual. The user can change the default settings (clock sources,
prescaler and frequency values). The clock tree is then updated accordingly. Invalid
settings and limitations are highlighted and documented with tool tips. Clock tree
configuration conflicts can be solved by using the solver feature. When no exact match
is found for a given user configuration, STM32CubeMX proposes the closest solution.
• Automatic updates of STM32CubeMX and STM32Cube MCU packages
STM32CubeMX comes with an updater mechanism that can be configured for
automatic or on-demand check for updates. It supports self-updates as well as
firmware library package updates. The updater mechanism also allows deleting
previously installed packages.
• Report generation
.pdf and .csv reports can be generated to document the user configuration work.
• Support of embedded software packages in CMSIS-Pack format (Software Packs)
STM32CubeMX allows getting and downloading updates of embedded software
packages delivered in CMSIS-Pack format. Selected software components belonging
to these new releases can then be added to the current project.
• Generating Software Packs with STM32PackCreator
STM32PackCreator is a graphical tool installed with STM32CubeMX in the Utilities
folder. It allows the user to create Software Packs and STM32Cube Expansion
packages enhanced for STM32CubeMX. It can be launched from the ST Tools tab
found in the 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 to install a JRE, whose 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.
Note: Upon successful installation, the STM32CubeMX icon is displayed on the desktop and the
application is available from the Program menu. STM32CubeMX .ioc files are displayed with
a cube icon, double-clicking on it opens the project in STM32CubeMX. Only the latest
installation of STM32CubeMX is enabled in the Program menu. Previous versions can be
kept on your PC (not recommended) when different installation folders have been specified.
Otherwise, the new installation overwrites the previous one(s).
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 standard console window to install for the current user, or the console window
with administrator rights to install for all users
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 16).
You can then launch the installation by typing, from a console window (with or without
administrator rights, according to your needs), the command:
SetupSTM32CubeMX-VERSION-Win.exe ABSOLUTE_PATH_TO_AUTO_INSTALL.xml
Several proxy types exist, and different 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 18 (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 19):
– 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.
Note: If STM32Cube MX is not connected to the network, or if STM32CubeMX detects a
connection failure, an icon is displayed close to the myST menu item showing that there is
no network connection. When the user clicks on that icon, “Configure network” menu is
displayed, and by clicking on it, the “Updater Settings/Connection parameters” dialog pops
up. Once the STM32CubeMX is connected to the network, the network icon disappears.
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 one of the
pack .pdsc file or from the vendor pack index (.pidx).
Proceed as follow:
a) Choose From URL … and click New (see Figure 23).
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 24).
c) Click the Check button to verify that the provided url is valid (see Figure 24).
d) Click OK. The pack pdsc information is now available in the user defined pack list
(see Figure 25).
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 27). When the
installation is successful, the check box turns green (see Figure 28).
The user can then add software components from this pack to its projects.
When the updater is configured for automatic checks, it regularly verifies if updates are
available.
When automatic checks have been disabled in the updater settings window, the user can
manually check if updates are available:
1. Click the icon to open the Update Manager window or Select Help > Check for
Updates. All the updates available for the user current installation are listed.
2. Click the check box to select a package, and then Install Now to download the update.
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 179). 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 STM32Cube 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®(a) 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 39). 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).
a. TrustZone is a registered trademark of Arm Limited (or its subsidiaries) in the US and/or elsewhere.
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 45):
• with STM32CubeMX (available only for examples listed with an STM32CubeMX
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 needed 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 47). A part number can also be entered partially:
STM32CubeMX proposes a list of matching products (see Figure 48).
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 49).
Figure 50. 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.
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 52).
Figure 52. 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 53).
• Six contexts are created in the configuration panel (see Figure 55)
• The Cortex-A35 runs under the OpenSTLinux operating system. It uses the following
firmware:
– TF-A BL2
– OP-TEE
– U-Boot
– Linux
• The Cortex-M33 is configured using Cube firmware: M33NS Cube FW (HAL & LL)
After assigning the IPs context go to “Project Manager” view, save the project, and generate
the code.
The second example uses the following boot mode: Cortex-A35 is the master processor,
Cortex-M33 core is the secondary one, in secure mode.
The master always runs in a secure mode.
• Select an STM32MP257x MPU
• Select the option “with A35 Master with Cortex M33 TrustZone activated?” on the
popup window (see Figure 57)
Cortex-A35 runs under the OpenSTLinux operating system. It uses the following firmware:
– TF-A BL2
– OP-TEE
– U-Boot
– Linux
Cortex-M33 secure is configured using Cube firmware: TF-M
To assign IPs context go to “Pinout & Configuration” and configure IPs.
After assigning the IPs context go to “Project Manager” view, save the project, and then
generate code.
As an example:
• OP-TEE is eligible to load the main processor.
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 63).
Clicking the details and documentation link (or CTRL+d) provides additional information
such as summary and reference documentation links (see Figure 64). For a given
peripheral, clicking Datasheet or Reference manual opens the corresponding document,
stored in STM32CubeMX repository folder, at the relevant chapter. Since microcontrollers
datasheets and reference manuals are downloaded to STM32CubeMX repository only upon
user request, a functional Internet connection is required:
• To check your Internet connection, open the Connection tab from the Help > Updater
Settings menu.
• To request the download of reference documentation for the currently selected
microcontroller, click Refresh from the Help > Refresh Data menu window.
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.
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 must 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 72).
Figure 72. 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.
This check can be bypassed 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 74).
Once a constant is defined, its name and/or its value can still be changed: double- click the
row that specifies the user constant to be modified. This opens the User Constants tab for
edition. The change of constant name is applied wherever the constant is used. This does
not affect the peripheral or middleware configuration state. However changing the constant
value impacts the parameters that use it and might result in invalid settings (such as
exceeding a maximum threshold). Invalid parameter settings are highlighted in fuchsia.
• 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 80).
Figure 81. 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
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
Set to a default value, can be configured when other choices are possible.
• GPIO maximum output speed (for communication peripherals only)
Set to Low by default for power consumption optimization, can be changed to a higher
frequency to fit application requirements.
• User Label
Changes the default name (such as 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 85).
As shown in Figure 86, 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 88). 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.
If an ISR does not use such functions, the checkbox can be unchecked and any priority level
can be set. It is possible to check/uncheck multiple rows (see rows highlighted in blue in
Figure 91).
Peripheral dedicated interrupts can also be accessed through the NVIC window in the
configuration window (see Figure 92).
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.
• 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 97).
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 97). 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 96.
/* 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 98.
When used as timebase source, a given peripheral is grayed and can no longer be selected
(see Figure 101).
As illustrated in the following examples, the selection of the HAL timebase source and the
use of FreeRTOS influence the generated code.
Figure 102. 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 103. NVIC settings when using FreeRTOS and SysTick as HAL timebase
As shown in the following code snippets, 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 104. NVIC settings when using FreeRTOS and TIM2 as HAL timebase
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.
For the STM32MP2 series, there is a unique RIF configuration provided to the user. The
radio button is disabled and indicates “No access” (see Figure 109): the user cannot read,
write, or use it in any form.
The Lock blocks any change after boot (that is, after configuration in STM32CubeMX), to
prevent software from subsequently making changes to the RIF elements.
The Local Lock defines a Lock on independent elements.
Global Lock defines a Lock on a set of elements. By default, it is OFF.
Configuration example
Figure 111 shows on left hand side the IP allocation per software context, and, on the
right-hand side the equivalent in the RISUP configuration panel.
For example, if the user sets ADC3 to Cortex-A35 secure context, on the RIF panel ADC3 is
allocated to CID 1, and set secure. The user can then configure the privilege and the lock. If
a peripheral is set in two contexts (Cortex-A35 and Cortex-M33), the allocated CID is 1&2.
If the user selects an IP in a Cortex-A35 non secure context and a Cortex-M33 non secure
context, the CID is set to 1&2 and the Secure column is unticked, as shown in Figure 113.
If the IP is not assigned to any software context, the CID column contain a –, and the Secure
column is unticked (in the case of Full Access).
Note: Some IPs in RISUP do not exist in peripheral list, and some IPs are coupled. They show-up
in the Peripheral column as one. As an example, ADC1 and ADC2 are shown as ADC12,
ICACHE and DCACHE are shown as ICACHE_DCACHE.
The features of the pseudo RIF-aware IPs are also visible in the RISUP table, as shown in
Figure 115.
If the user chooses to create a new project as full secure (Figure 117), the column “Secure”
is hidden, as all peripherals are working in secure mode (Figure 118).
Figure 117. Creation of a new project for the STM32N6 series - Secure projects
Figure 118. Peripherals (RISUP) panel for the STM32N6 series - Secure projects
Configuration example
In the following example, the FMC IP is configured to work as a RIF-aware IP:
• Click on FMC IP in Pinout & Configuration panel
• The FMC related features is displayed on the configuration panel on the right-hand side
• Select A35S (OP-TEE) for the features FMC_CFGR
• In the FMC Mode and Configuration panel, pick “NE1” in the “Chip select” drop down
• In the Configuration panel, three tabs are displayed (Parameter Settings, Features,
GPIO Settings)
1. IP name
2. IP id, which are unique
3. CID SELECTION, to select CID
4. Master CID, to change the CID value
5. Secure state, inherited from RISUP
6. PRIVILEGE state, when enabled
A global lock button on the top of RIMU table can be used to lock the RIMU.
To define a CID for an IP, activate CID SELECTION, and then choose a value from 0 to 6, as
shown in Figure 126.
To change the security or privilege value for an IP, activate the appropriate CID SELECTION
checkbox, as shown in Figure 127.
The inheritance relationship between RISUP and RIMU is established and valid only if the
IP is assigned to a context in the Pinout & Configuration panel.
In the context of inheritance relationships, the user cannot change the value of security and
privilege if they are false in RISUP, it can only change them from true to false if they are true.
Figure 130. Inheritance of CID, state of security, and privilege from RISUP
Note that:
• Some IPs have default values
• If the user does not have the right to change values in the RIMU, these cells are greyed
out
• If the user creates an STM32MP25xx project and selects the Cortex-M33 as the
master, M33S (secured) the global lock button is activated by default
• When an IP is not used (CID = -) and the user checks the related CID SELECTION, a
default value is assigned to the CID of the IP equal to the value of the TD CID
Figure 131. Default values for IPs and user modification restrictions
HSEM
HSEM is not configurable in STM32CubeMX, but it is visible in RIF Panel to show and
generate a default protection. It defines the filter access (secure and privilege) to HSEM
features (16 HSEM semaphores).
As the IP is not used in the system, the protection is not configurable and forced to the
“Default configuration”.
HSEM contains two tables, the first represents the CPU allocation per context, the second
contains the features, their “CPU Whitelist” (CPU_WL), the security states and privileges.
All the features (semaphores in case of HSEM IP) are secured and privileged, as shown in
Figure 133.
TAMP protection
TAMP for the STM32MP2 devices (Figure 134) contains two tabs:
• In the first, the user can configure the available resources, making them secure or
privileged.
• In the second, the user can configure the memory zone area storing critical
applications data.
– Each zone can be resized using a dedicated panel available in the RIF
configuration panel
– Each zone is associated to a resource: the resource assignment defines the
firmwares that can access a zone, and the access rights
For STM32N6 devices, the TAMP UI includes only a table that lists features along with their
security and privilege statuses (see Figure 135). Users can select a value between 0 and 32
to define the security level (in SECURE column) for the two features backup registers
protection offset (write, read/write) of the TAMP.
IPCC configuration
In the IPCC tab, the user can configure available resources, such as Resource features 0, 1
and 2, by setting their security levels or assigning privileged status.
PWR configuration
The PWR tab allows the user to manage settings for Resource 0, Resource 1, and
Resource 2, providing options to secure these resources, or grant them special privileges.
IO configuration
There are two main types of IO (input/output) configurations:
• Alternate function IO (AF IO): used to transmit signals that the peripherals process.
• General purpose IO (GPIO) and external Interrupt IO (EXTI IO): serve general
input/output functions and manage external interrupts.
For both types, security settings are automatically determined, based on their connections:
• For non-RIF-aware IPs, the security comes from the IP they are connected to
• For RIF-aware IPs, it is based on the specific features of the IP they are linked with
For GPIO and EXTI, the IO sets the security.
The assignments of IO to software contexts are displayed in the features panel specific to
the GPIO IP. Additionally, the security settings (RIF protection) for these IO configurations
can be found in the RIF-aware IP panel, under the GPIO sub-section
DMA configuration
For STM32MP2 MPUs, DMA channels can be secured to prevent unauthorized access.
Each channel is treated as a security feature within the DMA IP (integrated peripheral).
The approach to protecting DMA channels is similar to how IO protection is handled:
• The settings for which software contexts can use a DMA channel are determined by the
peripheral that needs the DMA service. These settings are then shown in the DMA
feature panel.
• The specific protection for each DMA channel is based on these settings and is
displayed in the RIF-aware IP panel, under the DMA section.
For STM32N6 MCUs, the security of DMA channels is user-defined and not automatically
inherited from the IPs, see Figure 141.
Clock configuration
Clock is a RIF-aware IP. Each clock is a RIF feature that can be protected thanks to the
software context assignments of the feature.
The feature protection is then reported in the RIF-aware IP RCC panel.
The RCC feature assignment follows a different scheme, dependent on its type.
Three clocks feature types exist:
• The root clocks:
– Their assignment is SOC family dependent.
– On STM32MP25 devices, these features are fixedly assigned to a unique context.
• The HW resource clocks (RAM or peripherals clocks)
– Their assignments are inherited from the HW resource assignments it clocks.
– These clocks may be associated to an additional configuration (the System Mode)
allowing to correctly protect the clock when it is shared between several CPU. This
is the case for STM32MP25 devices.
• The system resource clocks:
– These are the remaining clocks.
– Their configuration should be done manually from the feature panel of RCC IP.
Example of the clock protection of the HW resource BKPSRAM:
• For RCC the user can lock the features.
• Some features have a system mode, it is enabled if the feature has a CID equal to
“1&2” as we can see in case of BKPSRAM_CFGR feature above (Figure 146).
For STM32N6 devices, features security are not automatically configured, but are defined
by the user.
In the next we will cover only the RISAF, but the process is the same for RISAB. The first is
for managing internal memory and the second is for external memory.
RISAF configuration
RISAF is a mechanism allowing the user to configure memory access. Each memory is
divided into zones. Each zone can be configured to be read-only or read/write.
The user can also specify if privileges are required, if the memory zone should be secured
or encrypted.
The configuration happens at a compartment level.
Through RISAF registers, a trusted application (or the application to which the configuration
has been delegated) assigns memory regions and subregions to one or more security
domains (secure, privilege, compartment). RISAF includes the DDR memory.
Through RISAF the user can:
• See the list of the different memories
• Access the memory configuration
• Configure the parameters of the memory regions (Start address, region size, Master
CID, Read-Write-Privilege)
• Protect memory regions of DDR and external memories by clicking on the dedicated
memory.
RISAF includes four memories, namely RISAF1 (BKPSRAM), RISAF2 (OCTOSPI 1&2),
RISAF4 (DDR), and RISAF5 (PCIE).
Each memory table contains several columns, such as region ID, region name, start
address, region size in hexadecimal, seven groups for Master CID 0 to 6, secure and
encrypt.
For each subregion, the user can change the region name and the region size. Each
memory has its default configuration.
The region size should not exceed the total region memory, or a warning is displayed.
The user can assign a subregion to a master CID 0 to 6. CID 7 (not configurable in the UI) is
reserved for debugging.
OCTOSPI1&2 use the Memory mapped mode: the two controllers are sharing the same
256 MB memory region.
By default, OCTOSPI2 takes the whole region. By clicking on the region size cell of
mm_ospi1, a list appears, allowing the user to select the region size. Possible
configurations are 0/256, 64/192, 128/128, 192/64, and 256/0 MB (see Figure 154). The
start address changes automatically.
The master CID column group read/write/privilege are inherited from the RISUP table.
If the OCTOSPI1 peripheral in RISUP is assigned to CID1, Master CID group column 1 is
accessible, and the other CIDs are grayed out. If it is privileged in RISUP, it is privileged in
Master CID1 privilege column, as shown in Figure 156.
If OCTOSPI1 is secure in RISUP, it is secure and grayed out in RISAF2. The checkboxes
inherit their values from RISUP. Changes to the secure or to the privilege state must be
performed in the RISUP table.
If OCTOSPI1 is CID1&2 in RISUP, the two Master CID 1 and CID 2 are activated in RISAF2.
OCTOSPI2 is not assigned to any CID in RISUP, so the Master CID 0 is activated by default.
To change the memory size, go to the Pinout & Configuration tab, select the
DDR_CTRL_PHY, and choose the desired memory size.
When returning to RISAF4 (DDR) panel, a new configuration of the DDR memory appears
in table:
• The region sizes can be one of the following values: 521 Mbytes, 1 Gbyte, or 2 Gbytes,
depending on the user's choices.
• The number of regions decreases from 15 to 14.
• If the user decreases the size of a region, the decreased value is added to the size of
the linuxkernel1.
• There is no empty region in the new implementation.
• For the DDR 4 GBytes, if the user decreases the size of a region, the decreased value
is added to the size of the linuxkernel2.
As BKPSRAM memory, the user can assign a subregion to a master CID 0 to 6, set the
region as read / write, privilege, secure and encrypt.
RISAF configuration
RISAF is a mechanism allowing the user to configure memory access. Each memory is
divided into zones. Each zone can be configured to be read-only or read/write.
The user can also specify if privileges are required, if the memory zone should be secured
or encrypted.
The configuration happens at a compartment level.
Through RISAF registers, a trusted application (or the application to which the configuration
has been delegated) assigns memory regions and subregions to one or more security
domains (secure, privilege, compartment). RISAF includes the DDR memory.
Through RISAF the user can:
• See the list of the different memories
• Access the memory configuration
• Configure the parameters of the memory regions (Start address, region size, Master
CID, Read-Write-Privilege)
• Protect memory regions of DDR and external memories by clicking on the dedicated
memory.
The RISAF is divided into subcontrollers for 17 memory zones, which are assigned to
security domains through the RISAF subcontrollers listed below:
• RISAF1 (TCM)
• RISAF2 (CPU AXI RAM0)
• RISAF3 (CPU AXI RAM1)
• RISAF4 (NPU master 0)
• RISAF5 (NPU master 1)
• RISAF6 (CPU master)
• RISAF7 (FLEXRAM)
• RISAF8 (CACHE AXI RAM)
• RISAF9 (VENCRAM)
• RISAF11 (XSPI1)
• RISAF12 (XSPI2)
• RISAF13 (XSPI3)
• RISAF14 (FMC)
• RISAF15 (CACHEAXI configuration port)
• RISAF21 (AHB RAM1)
• RISAF22 (AHB RAM2)
• RISAF23 (Backup RAM)
Each RISAF subcontroller manages a specific number of memory regions. By default, it
controls seven regions, but some subcontrollers manage 11 regions, while others handle
only two regions.
In the user interface Each RISAF sub controller is represented by 2 tables: Memory regions
configuration and Memory sub-regions configuration.
Memory regions configuration table contains the following columns:
• Region ID: this column is non editable.
• Region name
• Start Address Offset and Region size: This value must be within a specific range for
each region. If the user sets an incorrect value, a popup appears indicating that the
value is out of range.
• Filtering
• Secure
• Read, Write, and Privilege: Values range from 0 to 255.
RISAF also covers the configuration of the memory sub-regions in the Memory sub-regions
configuration table. Each regions have two dedicated sub-regions (see Figure 164).
Subregions are not accessible by default (grayed). To activate a given subregion, activate
the related filtering parameter in the Memory regions configuration table (see Figure 165).
Memory sub-regions configuration table contains the following columns:
• RISAF region ID
• SubRegion name
• Start Address Offset and Region size: This value must be within a specific range for
each region. If the user sets an incorrect value, a popup appears indicating that the
value is out of range.
• SubRegion CID: Values range from 1 to 7.
• Filtering
• Delegated CID
• Delegation enabled
• Read
• Write
• Secure
• Privilege
• Lock
The generated code is placed in a file named <project name>-mx-rif.dtsi, which is part of the
master Secured firmware. Additionally, code relevant to the First Stage Bootloader (FSBL)
firmware is generated in a file named <project name>-mx-fw-config.dts.
The specific syntax and semantic rules for the generated code are detailed in the RIF
binding file. For more information, refer to the STM32MPU Wiki portal.
The next section details examples, including user interface screenshots and the
corresponding generated code snippets. The procedure is straightforward: configure the
RIF panels, click the GENERATE CODE button, and the code is produced in two files, with
the RIF configuration landing in a file named <project name>-mx-rif.dtsi.
For peripherals and middleware, these possibilities are offered in two different panels:
1. From the component tree panel, which lists all supported peripherals and middleware
(clicking the gear icon enables the “Show contexts” option), see Figure 169
2. From each component mode panel, opened by clicking the component name.
For GPIOs (see Figure 170), assignment is done through the Pinout view directly or later
and automatically through its selection in the platform settings panel of a middleware.
4.9.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.9.5), as shown in
Figure 172
• for each GPIO EXTI: in the GPIO configuration panel, as shown in Figure 173
• for each DMA channel: in the DMA configuration panel (see Section 4.9.4), as shown in
Figure 174.
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 175). 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 nonsecure context: channel, source and
destination cannot be secured (checkboxes are disabled) and so they are forced to the
nonsecure 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.9.5 GTZC
To configure TrustZone® system security, STM32L5 series come with a Global TrustZone®
security controller (GTZC). Refer to RM0438 “STM32L552xx and STM32L562xx advanced
Arm®-based 32-bit MCUs” 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 STM32CubeMX using
dedicated tabs in GTZC configuration panel:
• TZSC (TrustZone® security controller)
– Defines which peripherals are secured and/or privileged, and controls the
nonsecure 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.9.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 used clock signals are highlighted in
blue.
Out-of-range configured values are highlighted (as shown in Figure 180) to flag potential
issues. A solver feature is proposed to automatically resolve such configuration issues.
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 179 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.10.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 181).
Figure 181. 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 overdrive 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 enabled or disabled
– 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 184.
Note: Some project setting options become read-only once the project is saved. To modify these
options, the project must be saved as new, using the File > Save Project as menu.
Caution: STM32CubeMX uses reserved folder names. User cannot create new folder named
Middlewares or Utilities inside project folder generated by STM32CubeMX, because, after
code regeneration, those folders are deleted or modified.
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 189).
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 190).
Caution: STM32CubeMX manages firmware updates only 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).
Unselecting the Visibility (Static) option, as shown for MX_I2C1_init function in Figure 194,
allows the generation of the function definition without the static keyword, and hence
extends its visibility outside the current file (see Figure 195).
– Whether to import the project settings defined through the Project > Settings
menu: IDE selection, code generation options and advanced settings.
– Whether to import the project settings defined through the Project > Settings
menu: IDE selection and code generation options.
– Whether to attempt to import the whole configuration (automatic import) or only a
subset (manual import).
a) Automatic project import (see Figure 196)
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 198), 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 199 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 199).
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 202 and Figure 203 and check the limitation(s) in available peripheral
modes.
Figure 202. Set unused GPIO pins with Keep Current Signals Placement checked
Figure 203. Set unused GPIO pins with Keep Current Signals Placement unchecked
select Software Packs components for the current project. It features four panels, as shown
in Figure 204:
• Filters panel
Can be hidden using the “Show/hide filters” button. It is located on the left side of the
window and provides a set of criteria to filter the pack component list.
• Packs panel
Main panel, displays the list of software components per pack that can be selected.
• Component dependencies panel
Can be hidden using the “Show/hide dependencies” button. It displays dependencies, if
any, for the component selected in the packs panel. It proposes solutions when any is
found.
Dependencies that are not solved are highlighted with fuchsia icons.
Once the dependency is solved (by selecting a component among the solution
candidates) it is highlighted with green icons.
• Details and warnings panel
Can be hidden using the “Show/hide details” button. It is located on the right hand side.
It provide informations for the element selected in the Pack panel.
This element can be a pack, a bundle or a component. It offers the possibility to install
a version of the pack available but not yet installed, and allows the user to migrate the
current project to a newer version of the pack, raising incompatibilities that cannot be
automatically resolved.
See Section 10 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.
Details and warnings and Component dependencies panels are used to provide detailed
information.
The default view can be expanded by clicking the left arrows, revealing the next level, which
can be a Bundle or a top component. The lowest level is the component level.
From this panel, clicking an icon highlighting a limitation or an action opens the relevant
secondary panel (Details & Warnings or Component Dependency resolution).
Note: Some packs can have conditions on Arm® cores or STM32 series/MCUs, visible only when
the selected MCU meets the criteria. For example, a pack stating the “<accept
Dcore="Cortex-M4"/>” condition shows up, but is grayed for MCUs without Cortex®-M4
core.
Note: A pack may promote an API and be shown under the “exposed APIs” entry. Clicking the API
name allows to display additional information in the Details & warnings panel. Selecting the
component implementing the API selects the API itself. STM32CubeMX generates the
project with both the API .h definition file and the API implementation .c file.
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.
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 214). 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.
STM32H503x √ √ - - -
STM32H56x √ √ - - - -
STM32H57x √ √ √ √ √ √
STN32H523 √ √ - - - -
STM32H533 √ √ √ √ - -
STM32H7RSx √ √ √ √
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 STM32CubeMX), and programmed during the provisioning stage.
Optional NS application
DT56285V3
= OEM-iRoT
OEM-iRoT OEM-uRoT
S application
=1
TZEN OEM-iRoT OEM-uRoT
S application
Bootloader Bootloader
memory
DT56291V2
Reset
ST SFI/RSS ST SFI/RSS
Figure 219. Application boot paths (OEM-iRoT and secure manager projects)
2(0L5R7ĺ6HFXUH1RQVHFXUH 67L5R7ĺ67X5R7
user application ĺ6HFXUHPDQDJHUĺ
Nonsecure user application
NS-user application NS-user application
flash memory
Module S2
User
Bootloader Bootloader
System
DT56290V2
ST SFI/RSS ST SFI/RSS
(*) Source code not generated by STM32CubeMX
67L5R7ĺX5R7ĺ3URMHFWH[HFXWLRQ DVVHPEOHG
TLV MCU boot
NS user application
flash memory
Single image
(secure and nonsecure)
S user application
User
Bootloader
flash memory
System
Debug authentication
ST-iRoT (secure boot)
DT56421V3
Reset
ST SFI/RSS
Figure 221. Application boot path: ST-iRoT and uRoT secure/nonsecure project
67L5R7ĺX5R7ĺ6HFXUH1RQVHFXUHXVHUDSSOLFDWLRQ
16XVHUDSSOLFDWLRQ
S-user application
Bootloader
Debug authentication
DT56422V3
ST-iRoT (secure boot)
Reset
ST SFI/RSS
User flash
memory
NS-User application
Single image
(Secure and Nonsecure)
System flash S-User application
Bootloader
memory
Debug authentication
DT56423V2
ST-iRoT (secure boot)
Reset
ST SFI/RSS
NS-User application
S-User application
Bootloader
System flash
memory
Debug authentication
DT56423V3
ST-iRoT (secure boot)
Reset
ST SFI/RSS
NS-User application
User flash
Single image
memory
Bootloader
memory
Debug authentication
DT56425V2
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 activated ?” on the popup window, as shown below.
DT56296
S- and NS-application
code selected by default
IDE selection
DT56298V2
Firmware repository,
keep it for
STM32CubeMX
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 nonsecure codes.
DT56306V2
Complete boot
path displayed
DT56307V2
Figure 238. Project provisioning
DT56308V3
Note: If a selected boot path is not supported, a warning message is displayed, and the “FINISH”
button is grayed out.
Note: For STM32H56x and STM32H523x devices, it is not possible to configure the OEM-iRoT
boot path if the flash size of the current MCU is not aligned with the FLASH_SIZE entry in
the map.properties file. A pop-up window (see Figure 239) is displayed.
DT56309V4
Included in file map 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.
.
Click here to generate the code
and the IDE environment
DT56314V3
DT56316
Additional directories, including the IDE environment, are created.
DT56315V2
A secure application and a
nonsecure application
code have been generated
The S and NS applications can be developed using the generated code skeletons.
DT56317V3
xml configuration for secure application xml configuration for nonsecure application
The secure code must be generated before the nonsecure one. Compile each code
separately (right click on Project → Rebuild all). The secure and nonsecure signed and
encrypted binaries are generated during the post build phase.
In the user environment, STM32CubeMX has generated an env.bat file, containing the
information required for provisioning. Do not change this file.
A pop-up (see Figure 251) appears if you forget to compile the project OEMiRoT_Boot in
the CubeFW.
• Click “FINISH”, the boot path configuration panel is displayed (see Figure 254), 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
DT56335V3
ST-iRoT board provisioning
The program cannot be flashed using an IDE, use the provisioning scripts found in the user
environment.
• Double click on the provisioning.bat file (Figure 259)
• During provisioning, log files are generated to inform the user about the activity
• Follow the on-screen instructions (Figure 260)
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 266), use it to
configure the boot path in the “Boot Path and Debug Authentication” tab
• Press the “GENERATE CODE” button to generate the configuration code for the
selected toolchain
DT56336V2
Figure 268. Code is generated
DT56337V2
The nonsecure application can be developed using the generated code skeletons.
Post build
command added
DT56338V2
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.
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 275. 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.
Figure 283. First (left) and second (right) boot path stage
3. Enter the email address associated with your account in the dedicated field
(Figure 307).
4. Click on the “Reset my password” button (Figure 308). You will receive an email
containing a link to reset the password. If you do not receive the email within the next
few minutes, check your spam folder or contact our support team.
5. Click on the link in the email to access the password reset page.
6. Enter a new password in the dedicated field. Make sure that the new password is
strong and secure.
7. Confirm the new password by entering it again in the confirmation field.
8. Click on the "Submit" button to save the new password.
9. Log in to the application, using the new password.
If you suspect that your identity has been stolen, or that your account has been
compromised, it is important to change the password immediately to protect your account.
Follow the reset procedure described above to change it.
It is recommended to contact your ST referent to report any suspicious activity on your
account, and take necessary measures to protect it.
If you experience difficulties resetting the password, contact your ST referent for assistance.
5 STM32CubeMX tools
Figure 317. The result of comparing two projects having the same structure
Target table
The Target table (Figure 318) provides a comparison of the microcontroller’s parameters
used in each project. It clearly shows differences in:
• Part numbers
• Number of IOs
• Package types
• Core configurations
• Available flash memory sizes
The data is presented in this continuous table with hundreds of lines. It is composed of the
following columns:
• Category name
• IP name
• Mode
• Parameters settings
• Project 1
• Project 2
The “Peripherals & Middleware table includes a highlighting feature. This feature uses color
coding to visually differentiate parameters:
• Specific parameters for project 1 are marked in blue color
• Specific parameters for project 2 are marked in pink color
• The common parameters for the two projects are marked in black color
All peripheral categories are displayed collectively, with the option for sorting in alphabetical
order
Figure 321. Choosing the Excel format to save the comparison result
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 326).
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 330).
Importing pinout
Figure 331 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 332).
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 341. Current project configuration updated with new SMPS model
Figure 342. SMPS database management window with new model selected
Figure 343. SMPS transition checker and state diagram helper window
The Bluetooth Low-Energy mode can be selected from the left panel and configured to
reflect the application relevant settings. For each new step enabling BLE, the peripheral
consumption part is updated accordingly (see Figure 346). A similar approach is used for
ZigBee (see Figure 347).
The example can be changed anytime: the new sequence can be added to the current
sequence, or replace it (see Figure 351).
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 nonsecure” 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, select “1066E / 6-6-6” for faster DDR Speed Bin Grade, or
“1066G / 8-8-8” for a relaxed configuration.
Timing edition is 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, for Linux, use STSW-LINK007. 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 355).
Output/Log messages
STM32CubeMX outputs DDR suite related activity logs (see Figure 356) and interactive
protocol communication logs (see Figure 357). They are displayed by enabling outputs from
the Window menu.
This step is optional if the used U-Boot SPL already contains the required configuration. It
triggers 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.
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.
Linker files content is generated as if MMT is not used. SAU, GTZC, Cortex-M33 MPU, and
FLASH are enabled, so that the user can modify the values supplied by MMT.
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 369).
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 nonsecure one. The application
region allocated to the secure project is green, the nonsecure 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/nonsecure 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 373.
When going back to the MMT, a new region corresponding to the added FMC is created.
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 OCTOSPI1
to Cortex-M33 Secure. Choose Single SPI, and specify Device Size and Device Type.
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 nonsecure linker file
and check the same location for the memory regions allocated to the nonsecure area.
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.
For the new project created under STM32CubeMX the tool creates the default application
region to generate a valid project. The default data region can be updated by the user to
choose another region as RAM, but there must always be a default data region
(Figure 395).
5.5.4 STM32WBxx
Feature: MMT usage, pinout, and configuration user interface
When the first toggle button is ON, Cortex-M33 is under MMT control: its modes and
parameters become read-only (see Figure 402).
The user must select the Core and the STM32Cube firmware from a list. It is possible to
choose any STM32Cube firmware version (see Figure 403).
The list proposed to user contains only the firmwares found in
STM32Cube_FW_WB_Vx/Projects / STM32_Copro_Wireless_Binaries/STM32WBxx (all
.bin files). Firmware Update Service (FUS) and SafeBoot firmware are not proposed, so
they are not in the MMT list.
In this example, we loaded an STM32WB5x MCU, so the list must contain only
stm32wb5x_x binaries. the button “Refresh” is used to refresh the binaries list version
existing in the repository of STM32Cube firmware (see Figure 404).
After selecting the binary firmware, the MMT view is displayed and the reserved regions of
Cortex M0+ are created.
The middle panel represents the memory, split into two columns: the left one is the memory
seen by the core(s) Cortex-M4, the right one the memory set-up for the application.
For the new project created under STM32CubeMX the tool creates the default application
region to generate a valid project.
There are two possible configurations of the application regions for the code generation:
• First configuration:
• Second configuration:
The Cortex-M7 and Cortex-M4 contexts are managed by the MMT. Each context has its own
application region (AppReg0 and AppReg1, respectively).
User interface
The middle panel represents the memory, split into three columns: the left one is the
memory seen by the cores (CM7 and CM4), the middle one the memory set-up for the
application in Context Cortex-M7, the right one the memory set-up for the application in the
Context Cortex-M4.
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.
STM32CubeMX automatically adds a 4 Gbytes region for the system core, even if you are
not planning to use the MMT.
2. Click on the Start Project button, then choose Yes on the “Memory Protection Unit for
Cortex-M7” dialog box.
Note: STM32CubeMX applies the default configuration, then adds a 4 Gbytes region called
“Region 0” under the CORTEX_M7 parameters. The new parameters can be checked using
the Pinout and Configuration tab.
The default application regions are in exclusive mode (context sharing is unselected).
A reserved region in the other context will be created and mentioned as “Mx non-shared
region”.
4. Add a new region by pressing the “+” button that appears in the white space when
hovering with the mouse.
5. Select “Context sharing (M7, M4)”, automatically another region is created with the
same name, start address, and size
Figure 414. Configure the NVIC1, NVIC2 and select their HSEM global interrupt
Figure 417. The reserved memory regions for OPENAMP using MMT
9. Press the Generate Code button to generate code for both applications.
When the second radio button is on, the linker scripts for the CM7 and CM4 projects are
generated considering the configuration.
– To change the start address and the size of each region, update the ETH
parameters.
2. press the radio button “Apply Application region Settings to Peripherals ON” then ETH
will be partially under MMT control.
3. Press the Generate Code button to generate code for both applications.
Figure 423. The defined memories under the linker file (Cortex-M7)
Figure 424. The defined memories under the linker file (Cortex-M4)
5.5.6 STM32H7RS
Feature: MMT usage, pinout, and configuration user interface
When the first toggle button is ON, Cortex-M7_BOOT (MPU) and Cortex-M7_APPLI (MPU)
are under MMT control: their modes and parameters become read-only.
Only “Boot” and “Appli” contexts are managed by the MMT. Each context has its own
application region (AppReg0 and AppReg1, respectively).
User interface
The middle panel represents the memory, split into three columns: the left one is the
memory seen by the core(s), the middle one the memory set-up for the application in
Context Boot, the right one the memory set-up for the application in the Context Appli.
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.
STM32CubeMX automatically adds a 4 Gbytes region for the system core, even if you are
not planning to use the MMT.
2. Click on the Start Project button, then choose “Yes” on the “Memory Protection Unit for
Cortex-M7” dialog box.
STM32CubeMX applies the default configuration, then adds a 4-Gbyte region called
“Region 0” under the CORTEX_M7_BOOT parameters, and a 4-Gbyte region called
“Region 0” under the CORTEX_M7_APPLI parameters. The two regions start at the
same address, adjust it to avoid overlap.
The new parameters can be checked using the Pinout and Configuration tab.
The flash region overlap issue can be solved in different ways, the preferred one goes
through the following steps:
a) Select the Pinout and configuration tab
b) Enable XSPI1 for the boot context and choose the ‘Single SPI’ mode
In this example, on the Pinout & Configuration panel, Cortex-M7_BOOT (MPU) and
Cortex-M7_APPLI (MPU) are set and correspond to the region configuration on the Memory
Management Tool. They are grayed out, as they cannot be modified.
Three option bytes can be used to configure the regions in the MMT. To see them, activate
the IP FLASH on the Pinout and Configuration tab.
5.5.7 STM32WB0
Feature: MMT usage, pinout, and configuration user interface
When the first toggle button is ON, Cortex-M0+ (MPU) is under MMT control: its modes and
parameters become read-only (see Figure 446).
User interface
The middle panel represents the memory, split into two columns: the left one is the memory
seen by the core Cortex-M0+, the right one the memory set-up for the application.
For a new project created under STM32CubeMX, the MMT creates the default application
region to generate a valid project.
The linker files are copied from STM32Cube firmware of boot path, and MMT integrates all
added application regions ("App_User").
• Open the linker files STM32H7S3I8KX_OEMiROT_Appli_app.ld or
STM32H523CETX_FLASH.ld (respectively, left or right side of Figure 452)
• Look at the memory definition: check the "App_User" declaration in the Appli project in
case of an OEM-iRoT boot path (see Figure 453 and Figure 454).
Figure 452. Linker files location (STM32H7RS on the left, STM32H5 on the right)
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 457, 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 is
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 21. 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 22. LL versus HAL code generation: STM32CubeMX generated header files
Generated Mix of HAL
HAL only LL only Comments
header files and LL
Table 24. LL versus HAL: STM32CubeMX generated functions and function calls
Generated
HAL only LL only Mix of HAL and LL Comments
source files
Table 24. LL versus HAL: STM32CubeMX generated functions and function calls (continued)
Generated
HAL only LL only Mix of HAL and LL Comments
source files
Figure 463. 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 466)
• the stm32f4xx_hal_conf.h file in the project Inc folder (see Figure 467)
• the project view within EWARM user interface as shown in Figure 468 and Figure 469.
Figure 468. 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.8: Pinout & Configuration view for STM32H7 dual-core
products for details).
Figure 471. 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)
• Makefile (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 nonsecure images can be built.
Figure 472. Building secure and nonsecure images with ARMv8-M TrustZone®
When TrustZone® is enabled for the project, STM32CubeMX generates three folders:
• NonSecure for nonsecure code
• Secure for secure code
• Secure_nsclib for nonsecure callable region
See Figure 473 (use TZ_BasicStructure_project_inCubeIDE.png) and Figure 474 (use
STM32L5_STM32CubeMX_Project_settings_inCubeIDE.png).
Figure 473. 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 STM32MPUs 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 478). 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 483).
Optionally, remove the MCUs Selection bottom window by deselecting Window > Outputs
submenu (see Figure 484).
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 486).
c) You can also configure the RCC to use an external oscillator as potential clock
source (see Figure 487).
Answering No will require to provide a name and location for the report only.
As shown in Figure 490, 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. Select the clock source (HSE, HSI or PLLCLK) that will drive the system clock.
In the example taken for the tutorial, select HSI to use the internal 16 MHz clock (see
Figure 492).
To use an external clock source (HSE or LSE), the RCC peripheral must be configured
in the Pinout view, as pins will be used to connect the external clock crystals (see
Figure 493).
– 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, RNG and SDIO clocks are driven by an independent PLL output.
– 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 (for example, set all free pins as analog I/Os to reduce power
consumption).
In the tutorial example, select the settings as displayed in Figure 510, 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 528). The Pinout view is
loaded, matching the MCU pinout configuration on the evaluation board (see
Figure 529).
7. From the Peripheral tree on the left, expand the SDIO peripheral and select “SD 4 bits
wide bus” (see Figure 530). 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 531).
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 532).
b) Configure the clock tree from the clock tab (see Figure 533).
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 535). 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 STM32CubeMX
User interface (under Linker Settings from Project Manager's project tab), adjust the
heap and stack sizes (see Figure 536).
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 538). 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 538.
– 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 539).
– Some peripherals for which consumption is unavailable or negligible are
highlighted with ‘*’ (see Figure 539).
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 541).
See Figure 547 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 550).
3. Select the Asynchronous mode for the USART2 peripheral (see Figure 551).
4. Check that the signals are properly assigned on pins (see Figure 552):
– 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 553).
3. Click TIM2 and change the prescaler to 16000, the Word Length to 8 bits and the
Counter Period to 1000 (see Figure 555).
4. Enable TIM2 global interrupt from the NVIC Settings tab (see Figure 556).
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 560).
3. The Tera Term window displays a message coming from the board at a period of a few
seconds (see Figure 561).
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 563 and Figure 564).
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 564
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 563 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 564 for an
example).
Figure 564. 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 567. 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 569),
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 571)
• 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 572).
• Mobile application (see Figure 573): 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 578):
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 584 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 596: 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 597).
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 599, 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 600)
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 601), 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 603).
Figure 604. 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);
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 615 and Figure 616).
Figure 619. 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 620).
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 622).
Unchecking allows STM32CubeMX shifting blocks around
and freeing a block for the Ethernet MII mode. (see Figure 623).
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 624).
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 626).
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 630: 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 631: Enabling the TouchSensing
peripheral, Figure 632: Touch-sensing sensor selection panel and Figure 633:
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 643 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 644). 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.