MANUAL USUARIO STM32cubeMX
MANUAL USUARIO STM32cubeMX
User manual
STM32CubeMX for STM32 configuration
and initialization C code generation
Introduction
STM32CubeMX is a graphical tool for STM32 microcontrollers. It is part of the
STM32Cube™ initiative (see Section 2) and is available either as a standalone application
or as an Eclipse plug-in for integration in Integrated Development Environments (IDEs).
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: STM32Cube embedded software packages for details on
the STM32Cube embedded software offer)
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 implementations of microcontroller peripherals and
firmware.
The following documents are available from www.st.com:
STM32 microcontroller reference manuals and datasheets
STM32Cube HAL/LL driver user manuals for STM32F0 (UM1785), STM32F1
(UM1850), STM32F2 (UM1940), STM32F3 (UM1786), STM32F4 (UM1725), STM32F7
(UM1905), STM32L0 (UM1749), STM32L1 (UM1816), STM32L4/L4+ (UM1884) and
STM32H7 (UM2217).
Contents
1 General information . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
2 STM32Cube overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
11.7 Updating the project with the user application code . . . . . . . . . . . . . . . . 259
11.8 Compiling and running the project . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 260
11.9 Configuring Tera Term software as serial communication
client on the PC . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 260
17 FAQ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 292
17.1 On the Pinout configuration panel, why does STM32CubeMX
move some functions when I add a new peripheral mode? . . . . . . . . . . 292
17.2 How can I manually force a function remapping? . . . . . . . . . . . . . . . . . 292
17.3 Why are some pins highlighted in yellow or in light green in
the Chip view? Why cannot I change the function of some
pins (when I click some pins, nothing happens)? . . . . . . . . . . . . . . . . . . 292
17.4 Why do I get the error “Java 7 update 45” when installing
“Java 7 update 45” or a more recent version of the JRE? . . . . . . . . . . . 292
17.5 Why does the RTC multiplexer remain inactive on the Clock tree view? 293
17.6 How can I select LSE and HSE as clock source and
change the frequency? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 294
17.7 Why STM32CubeMX does not allow me to configure PC13,
PC14, PC15 and PI8 as outputs when one of them
is already configured as an output? . . . . . . . . . . . . . . . . . . . . . . . . . . . . 294
List of tables
List of figures
Figure 47. Set unused GPIO pins with Keep Current Signals Placement checked . . . . . . . . . . . . . . . 73
Figure 48. Set unused GPIO pins with Keep Current Signals Placement unchecked . . . . . . . . . . . . . 74
Figure 49. Project Settings window . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75
Figure 50. Project folder. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76
Figure 51. Selecting basic application structure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78
Figure 52. Selecting advanced application structure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79
Figure 53. Selecting a different firmware location . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80
Figure 54. Firmware location selection error message . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80
Figure 55. Recommended new firmware repository structure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81
Figure 56. Project Settings Code Generator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83
Figure 57. Template Settings window . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 84
Figure 58. Generated project template . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85
Figure 59. Advanced Settings window . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86
Figure 60. Generated init functions without C language “static” keyword . . . . . . . . . . . . . . . . . . . . . . 86
Figure 61. Additional software components - collapsed view showing packs and bundles . . . . . . . . . 88
Figure 62. Additional software components - expanded view showing component details . . . . . . . . . 89
Figure 63. Dependency solving: solution found . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91
Figure 64. Dependency solving: no solution found . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91
Figure 65. Software components conditions - Solution proposals and guidance . . . . . . . . . . . . . . . . 92
Figure 66. Software components conditions resolved . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92
Figure 67. Selection of additional software components . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93
Figure 68. Additional software components - Updated tree view. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93
Figure 69. About window . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 94
Figure 70. STM32CubeMX Pinout view . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 95
Figure 71. Contextual Help Window (default) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 96
Figure 72. Contextual Help detailed information . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97
Figure 73. Chip view . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99
Figure 74. Red highlights and tooltip example - no mode configuration available . . . . . . . . . . . . . . . 103
Figure 75. Orange highlight and tooltip example - some configurations unavailable. . . . . . . . . . . . . 103
Figure 76. Tooltip example - all configurations unavailable . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103
Figure 77. Modifying pin assignments from the Chip view. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 104
Figure 78. Example of remapping in case of block of pins consistency. . . . . . . . . . . . . . . . . . . . . . . 105
Figure 79. Pins/Signals Options window . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 107
Figure 80. Selecting a HAL timebase source (STM32F407 example) . . . . . . . . . . . . . . . . . . . . . . . . 108
Figure 81. TIM2 selected as HAL timebase source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 108
Figure 82. NVIC settings when using SysTick as HAL timebase, no FreeRTOS . . . . . . . . . . . . . . . 109
Figure 83. NVIC settings when using FreeRTOS and SysTick as HAL timebase . . . . . . . . . . . . . . 110
Figure 84. NVIC settings when using FreeRTOS and TIM2 as HAL timebase . . . . . . . . . . . . . . . . . 112
Figure 85. STM32CubeMX Configuration view . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 113
Figure 86. Configuration window tabs for GPIO, DMA and NVIC settings (STM32F4 Series) . . . . . 114
Figure 87. Peripheral Configuration window (STM32F4 Series) . . . . . . . . . . . . . . . . . . . . . . . . . . . . 115
Figure 88. User Constants window . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 118
Figure 89. Extract of the generated main.h file . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 119
Figure 90. Using constants for peripheral parameter settings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 119
Figure 91. Specifying user constant value and name . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 120
Figure 92. Deleting user constant not allowed when the
constant is already used for another constant definition. . . . . . . . . . . . . . . . . . . . . . . . . . 121
Figure 93. Deleting an user constant used for parameter configuration -
Confirmation request . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 121
Figure 94. Deleting a user constant used for peripheral configuration -
Consequence on peripheral configuration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 122
Figure 95. Searching for a name in a user constant list. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 122
Figure 144. SMPS database management window with new model selected. . . . . . . . . . . . . . . . . . . 175
Figure 145. SMPS transition checker and state diagram helper window. . . . . . . . . . . . . . . . . . . . . . . 176
Figure 146. Configuring the SMPS mode for each step . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 177
Figure 147. Labels for pins generating define statements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 179
Figure 148. User constant generating define statements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 179
Figure 149. Duplicate labels . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 179
Figure 150. HAL-based peripheral initialization: usart.c code snippet . . . . . . . . . . . . . . . . . . . . . . . . . 184
Figure 151. LL-based peripheral initialization: usart.c code snippet . . . . . . . . . . . . . . . . . . . . . . . . . . 185
Figure 152. HAL versus LL : main.c code snippet . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 185
Figure 153. extra_templates folder – default content. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 187
Figure 154. extra_templates folder with user templates . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 188
Figure 155. Project root folder with corresponding custom generated files . . . . . . . . . . . . . . . . . . . . . 188
Figure 156. User custom folder for templates . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 189
Figure 157. Custom folder with corresponding custom generated files . . . . . . . . . . . . . . . . . . . . . . . . 189
Figure 158. Update of the project .ewp file (EWARM IDE)
for preprocessor define statements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 191
Figure 159. Update of stm32f4xx_hal_conf.h file to enable selected modules . . . . . . . . . . . . . . . . . . 192
Figure 160. New groups and new files added to groups in EWARM IDE . . . . . . . . . . . . . . . . . . . . . . 192
Figure 161. Preprocessor define statements in EWARM IDE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 193
Figure 162. Selecting a CMSIS-Pack software component . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 195
Figure 163. Enabling a CMSIS-Pack software components . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 196
Figure 164. Enabling and configuring a CMSIS-Pack software component . . . . . . . . . . . . . . . . . . . . 196
Figure 165. Project generated with CMSIS-Pack software component . . . . . . . . . . . . . . . . . . . . . . . . 197
Figure 166. MCU selection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 198
Figure 167. Pinout view with MCUs selection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 199
Figure 168. Pinout view without MCUs selection window . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 200
Figure 169. GPIO pin configuration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 201
Figure 170. Timer configuration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 201
Figure 171. Simple pinout configuration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 202
Figure 172. Save Project As window . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 202
Figure 173. Generate Project Report - New project creation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 203
Figure 174. Generate Project Report - Project successfully created . . . . . . . . . . . . . . . . . . . . . . . . . . 203
Figure 175. Clock tree view . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 204
Figure 176. HSI clock enabled . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 205
Figure 177. HSE clock source disabled . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 205
Figure 178. HSE clock source enabled . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 205
Figure 179. External PLL clock source enabled . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 205
Figure 180. Configuration view . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 207
Figure 181. Case of Peripheral and Middleware without configuration parameters. . . . . . . . . . . . . . . 207
Figure 182. Timer 3 configuration window . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 208
Figure 183. Timer 3 configuration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 209
Figure 184. Enabling Timer 3 interrupt . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 210
Figure 185. GPIO configuration color scheme and tooltip . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 210
Figure 186. GPIO mode configuration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 211
Figure 187. DMA Parameters configuration window . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 212
Figure 188. FatFs disabled . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 212
Figure 189. USB Host configuration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 213
Figure 190. FatFs over USB mode enabled . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 213
Figure 191. Configuration view with FatFs and USB enabled . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 213
Figure 192. FatFs peripheral instances . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 214
Figure 193. FatFs define statements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 214
Figure 194. Project Settings and toolchain selection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 215
1 General information
2 STM32Cube overview
a. Arm is a registered trademark of Arm Limited (or its subsidiaries) in the US and/or elsewhere.
3.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.
directly imported as a new project within third party IDE (IAR™ EWARM, Keil™
MDK-ARM, Atollic® TrueSTUDIO® and AC6 System Workbench for STM32).
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 STM32CubeMX self-updates
as well as STM32Cube firmware library package updates. The updater mechanism
also allows deleting previously installed packages.
Report generation
.pdf and .csv reports can be generated to document user configuration work.
Please update section 3.2 with the following new features:
Graphics simulator
For graphics-capable microcontrollers, STM32CubeMX allows simulating a graphics
configuration and adjusting graphics parameters to optimize the performance. Once
the results are satisfactory, the current project configuration can be adjusted
accordingly.
Support of embedded software packages in CMSIS-Pack format
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.
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.
Interactive mode
To perform interactive installation, type the following command:
java –jar SetupSTM32CubeMX-4.14.0.exe –console
At each installation step, an answer is requested (see Figure 2).
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 installation
preferences (see Figure 3):
You can then launch the installation by typing the following command:
java –jar SetupSTM32CubeMX-4.14.0.exe auto-install.xml
exit
To run STM32CubeMX in command-line mode getting commands from a scripts and
without UI, use the following command line:
– On Windows:
java -jar STM32CubeMX.exe –q <script filename>
– On Linux and macOS:
java -jar STM32CubeMX –q <script filename>
Here again, the user can enter commands when the MX prompt is displayed.
See Table 1 for available commands.
To view Windows default proxy settings, select Internet options from the Control panel and
select LAN settings from the Connections tab (see Figure 11).
Several proxy types exist and different computer network configurations are possible:
Without proxy: the application directly accesses the web (Windows default
configuration).
Proxy without login/password
Proxy with login/password: when using an Internet browser, a dialog box opens and
prompts the user to enter its login/password.
Web proxies with login/password: when using an Internet browser, a web page opens
and prompts the user to enter its login/password.
If necessary, contact your IT administrator for proxy information (proxy type, http address,
port).
STM32CubeMX does not support web proxies. In this case, the user will not be able to
benefit from the update mechanism and will need to 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 12 (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 13):
– No Proxy
– Use System Proxy Parameters
On Windows, proxy parameters will be retrieved from the PC system settings.
Uncheck “Require Authentication” if a proxy server without login/password
configuration is used.
6. Select Help > Install New Libraries submenu to select among a list of possible
packages to install.
7. If the tool is configured for manual checks, select Help > Check for Updates to find out
about new tool versions or firmware library patches available to install.
2. Click From Local … button to browse the computer filesystem and select an
embedded software package. STM32Cube MCU packages come as zip archives and
embedded software packs come as .pack archives.
This action is required in the following cases:
– No Internet access is possible but the embedded software package is available
locally on the computer.
– The embedded software package is not public and hence not available on
Internet. For such packages, STM32CubeMX cannot detect and propose updates.
3. Click From URL… button to specify the download location from Internet for either one
of the pack .pdsc file or the vendor pack index (.pidx).
Proceed as follow:
a) Choose From URL … and click New (see Figure 16).
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 17).
c) Click the Check button to verify that the url provided is valid (see Figure 17).
Figure 17. Checking the validity of vendor pack .pdsc file url
d) Click OK. The pack pdsc information is now available in the user defined pack list
(see Figure 18).
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
(see Figure 19).
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 20). When the
installation is successful, the check box turns green (see Figure 21).
The user will then be able to add software components from this pack to its
projects.
STM32CubeMX user interface consists first of a welcome page from which the user decides
to start a new project or load a recent one, then of a new project window in which the user
shall select a board or microcontroller part number to be used for the project, and finally the
project view with its main window, its menu bar, its toolbar, four configuration views (Pinout,
Configuration, Clock Configuration, Power Consumption Calculator) and a set of help
windows (MCUs selection, Update manager, About). All these user interface components
are described 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. Select the relevant features (peripherals, middlewares) and their operating modes from
the Pinout view.
2. Configure the clock tree from the clock configuration view.
In the Pinout 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 tree view (see Figure 33).
3. Configure the parameters required to initialize the peripherals and middleware
operating modes from the configuration view.
4. Generate the initialization C code.
This shortcut launches STM32CubeMX new project creation by opening the New
New Project project window (select an MCU from the MCU selector tab or a board configuration
from the Board selector tab).
This shortcut opens a browser window to select a previously saved configuration
(.ioc file) and loads it.
When loading a project created with an older STM32CubeMX version, the user can
either select migrate to migrate it to the latest STM32CubeMX available database
and STM32Cube firmware version or continue.
Caution: Prior to STM32CubeMX 4.17, clicking continue still upgrades to the latest
Load Project database “compatible” with the SMT32Cube firmware version used by the
project.
Starting from STM32CubeMX 4.17, clicking continue keeps the database
used to create the project untouched. If the required database version is
not available on the computer, it will be automatically downloaded.
Caution: 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 This shortcut opens the user manual.
MCU selection
The MCU selector allows filtering on a combination of criteria: series, lines, packages,
peripherals, on additional MCU characteristics such as price, memory size or number of
I/Os (see Figure 27) and on MCU graphics capabilities as well.
column. Moreover, selecting an MCU from this list will allow to use graphical stacks in
the project.
3. A graphics summary panel, showing the minimum requirements for pixel clock and
graphics RAM size to meet the selected graphics criteria.
It also displays the performance ranges (maximum system clock and Graphics
performance score) that can be achieved with the current list of MCUs.
Parameters descriptions are provided in tooltips (to display: hover the mouse over the
parameter name).
Figure 30. New Project window - MCU list with close MCUs function
Figure 31. New Project window - MCU list showing close MCUs
Note: A matching percentage is computed for each user selected criteria, for example:
- When requesting four instances of the CAN peripheral, the MCUs with only three instances
will reach a 75% match on the CAN criteria.
- If the maximum price criteria is selected, the matching ratio for a given MCU will be the
maximum requested price divided by the actual MCU price. In the case of a minimum price
criteria, the matching ratio will be the MCU price divided by the minimum requested price.
Finally, all criteria ratios are averaged to give the Match column percentage value.
The Board selector allows filtering on STM32 board types, Series and peripherals (see
Figure 32). Only the default board configuration is proposed. Alternative board
configurations obtained by reconfiguring jumpers or by using solder bridges are not
supported.
When a board is selected, the Pinout view is initialized with the relevant MCU part number
along with the pin assignments for the LCD, buttons, communication interfaces, LEDs, and
other functions (see Figure 34). Optionally, the user can choose to initialize it with the
default peripheral modes (see Figure 35).
When a board configuration is selected, the signals change to 'pinned', i.e. they cannot be
moved automatically by STM32CubeMX constraint solver (user action on the peripheral
tree, such as the selection of a peripheral mode, will not move the signals). This ensures
that the user configuration remains compatible with the board.
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 34).
Selecting a board, then 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 will generate the C initialization code for all the
peripherals available on the board and not only for those relevant to the user application
(see Figure 35).
No icon Close Project Closes the current project and switches back to the welcome page.
Recent
No icon Displays the list of five most recently saved projects
Projects >
No icon Exit Proposes to save the project if needed, then closes the application.
Show user Allows showing on the Chip view, the user-defined labels
labels instead of the names of the signals assigned to the pins.
Best Fit Adjusts the chip pinout diagram to the best fit size
Rotate Rotates the MCU core as well as its pins and mapped signals by
clockwise 90 degrees clockwise or counterclockwise from the current view.
Counter Click twice to rotate by 180 degrees, and three times to rotate by
clockwise 270 degrees.
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 44).
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 will be 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 will not be
moved and the number of possible peripheral modes becomes limited.
Refer to Figure 47 and Figure 48 and check the limitation in available peripheral
modes.
Figure 47. Set unused GPIO pins with Keep Current Signals Placement checked
Figure 48. Set unused GPIO pins with Keep Current Signals Placement unchecked
3. By selecting Save As for a project that includes C code generation (and not only pin
configuration).
Note: Some project settings options become read-only once the project is saved. To modify these
options, the project must be saved as a new project using the File> Save Project as menu.
The new location should 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 54).
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 55).
Caution: STM32CubeMX manages firmware updates solely for this default location. Choosing
another location will prevent 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 will be generated accordingly (see Section 6.2:
STM32Cube code generation using Low Layer drivers).
Unselecting the Visibility (Static) option, as shown for MX_I2C1_init function in Figure 59,
allows the generation of the function definition without the static keyword and hence extends
its visibility outside the current file (see Figure 60).
There are no component names. Instead, each component is uniquely identified for a given
vendor pack by the combination of class name, group name and a version. Additional
categories, such as sub-group and variant can be assigned.
By default, the window shows a component list grouped by vendor name (first column) and
pack or bundle version (second column). Refer to Figure 61 for an example.
Figure 61. Additional software components - collapsed view showing packs and bundles
Clicking the button expands the view and displays all software components details (see
Figure 62).
Figure 62. Additional software components - expanded view showing component details
Optional field for software components that come in different variants (such as
Variant
debug and release).
Condition Short name describing the condition (such as CMSIS-RTOS Dependencies).
Status of the condition to be met (see Table 9 for the different condition statuses).
Status
Clicking the status opens the condition description in the bottom panel.
Description Software component short description.
1. The Arm® Keil™
CMIS-Pack website, http://www.keil.com, lists the following classes:
Data Exchange: Software components for data exchange
File System: File drive support and file system
Graphics: Graphic libraries for user interfaces
Network: Network stack using Internet protocols
RTOS: Real-time operating systems
Safety: Components for testing application software against safety standards
Security: Encryption for secure communication or storage
USB: Universal serial bus stack
Wireless: Communication stacks such as Bluetooth™, WiFi®, and ZigBee®.
1. Click the condition status icon to display the conditions to be solved in the bottom
panel, together with their description and the software component that could solve the
issue, if any (see Figure 63 and Figure 64).
2. Clicking a proposed solution in the bottom panel highlights the software component
selection checkbox in the component table above (see Figure 65).
3. Selecting the recommended software component resolves the condition. The condition
status changes to resolved, , (see Figure 66).
The current selection of additional software components appears in the tree view (see
Figure 68).
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 71).
Clicking the details and documentation link (or CTRL+d) provides additional information
such as summary and reference documentation links (see Figure 72). 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
users’ 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.
Table 10. Peripheral and Middleware tree panel - icons and color scheme
Display Peripheral status
Table 10. Peripheral and Middleware tree panel - icons and color scheme
Table 11. STM32CubeMX Chip view - Icons and color scheme (continued)
Display Pin information
Table 11. STM32CubeMX Chip view - Icons and color scheme (continued)
Display Pin information
Tooltips
Move the mouse over peripherals and peripheral modes that are unavailable or partially
available to display the tooltips describing the source of the conflict that is which pins are
being used by which peripherals.
As an example (see Figure 74), the Ethernet (ETH) peripheral is no longer available
because there is no possible mode configuration left. A tooltip indicates to which signal are
assigned the pins required for this mode (ADC1-IN0 signal, USART3 synchronous signal,
etc...).
Figure 74. Red highlights and tooltip example - no mode configuration available
In the next example (see Figure 75), the SDIO peripheral is partially available because at
least one of its modes is unavailable: the necessary pins are already assigned to the I2C
mode of the I2C3 peripheral.
Figure 75. Orange highlight and tooltip example - some configurations unavailable
In this last example (see Figure 76) I2C2 peripheral is unavailable because there is no
mode function available. A tooltip shows for each function where all the remapped pins have
been allocated (USART3 synchronous mode).
Tip
If a mode becomes unavailable (highlighted in red), try to find another pin remapping
configuration for this mode by following the steps below:
1. From the Chip 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.
this signal can be moved to another pin, provided the Keep user placement option
is unchecked.
c) Select Enter User Label to specify a user defined label for this signal. The new
label will replacing the default signal name in the Chip view.
2. From the Pinout menu, select Pins/Signals Options
The Pins/Signals Options window (see Figure 79) lists all configured pins.
a) Click the first column to individually pin/unpin signals.
b) Select multiple rows and right-click to open the contextual menu and select
Signal(s) Pinning or Unpinning.
c) Select the User Label field to edit the field and enter a user-defined label.
d) Order list alphabetically by Pin or Signal name by clicking the column header.
Click once more to go back to default i.e. to list ordered according to pin
placement on MCU.
Note: Even if a signal is pinned, it is still possible however to manually change the pin signal
assignment from the Chip view: click the pin to display other possible signals for this pin and
select the relevant one.
Using the SysTick remains acceptable if the application respects the HAL programming
model, that is, does not perform any call to HAL timebase services within an Interrupt
Service Request context (no dead lock issue).
To change the HAL timebase source, go to the SYS peripheral in the Peripheral and
Middleware tree panel and select a clock among the available clock sources: SysTick,
TIM1, TIM2,... (see Figure 80).
When used as timebase source, a given peripheral is grayed and can no longer be selected
(see Figure 81).
As illustrated in the following examples, the selection of the HAL timebase source and the
use of FreeRTOS influence the generated code.
Figure 82. 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 */
Figure 83. NVIC settings when using FreeRTOS and SysTick as HAL timebase
As shown in the code snippets given below, the SysTick interrupt handler is updated to use
CMSIS-os osSystickHandler function.
main.c file
/* SysTick_IRQn interrupt configuration */
HAL_NVIC_SetPriority(SysTick_IRQn, 15, 0);
stm32f4xx_it.c file
/**
* @brief This function handles System tick timer.
*/
void SysTick_Handler(void)
{
/* USER CODE BEGIN SysTick_IRQn 0 */
Figure 84. NVIC settings when using FreeRTOS and TIM2 as HAL timebase
GPIO, DMA and NVIC settings can be accessed either via a dedicated button like other
peripherals or via a tab in the other configuration windows of the peripherals which use them
(see Figure 86).
Figure 86. Configuration window tabs for GPIO, DMA and NVIC settings (STM32F4 Series)
Table 13. Peripheral and Middleware Configuration window buttons and tooltips
Buttons and messages Action
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.
Tooltip
Table 13. Peripheral and Middleware Configuration window buttons and tooltips
Buttons and messages Action
Table 13. Peripheral and Middleware Configuration window buttons and tooltips
Buttons and messages Action
If the value entered by the user is out of range, an the error will be
highlighted in red along with an explanatory tooltip:
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 will result in a invalid peripheral or middleware configuration (see Figure 93).
Click a row or select a set of rows to display the corresponding GPIO parameters (see
Figure 98):
GPIO PIN state
It changes the default value of the GPIO Output level. It is set to low by default and can
be changed to high.
GPIO mode (analog, input, output, alternate function)
Selecting a peripheral mode in the Pinout view automatically configures the pins with
the relevant alternate function and GPIO mode.
GPIO pull-up/pull-down
It is set to a default value and can be configured when other choices are possible.
GPIO maximum output speed (for communication peripherals only)
It is set to Low by default for power consumption optimization and can be changed to a
higher frequency to fit application requirements.
User Label
It changes the default name (e.g. GPIO_input) into a user defined name. The Chip
view is updated accordingly. The GPIO can be found under this new name via the Find
menu.
The Group by Peripherals checkbox allows to group all instances of a peripheral under the
same window (see Figure 99).
As shown in Figure 100, 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, etc....
The DMA request (called channel for STM32F4 MCUs) is used to reserve a stream to
transfer data between peripherals and memories (see Figure 102). The stream priority will
be 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 post-incremented 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) Then, 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 a destination memory.
When FreeRTOS is enabled, an additional column is shown (see Figure 105). In this case,
all the interrupt service routines (ISRs) that are calling the interrupt safe FreeRTOS APIs,
should have a priority lower than the priority defined in the
LIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY parameter (the highest the value, the
lowest the priority). The check in the corresponding checkbox guarantees that the restriction
is applied.
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 at a time (see rows highlighted in blue in
Figure 105).
Peripheral dedicated interrupts can also be accessed through the NVIC window in the
Peripheral Configuration window (see Figure 106).
For some peripherals, the application still needs to call another function to actually
activate the interruptions. Taking the timer peripheral as an example, the
HAL_TIM_IC_Start_IT function needs to be called to start the Timer input capture (IC)
measurement in interrupt mode.
Configuration of interrupts initialization sequence
Checking Select for Init sequence ordering for a set of peripherals moves the
HAL_NVIC function calls for each peripheral to a same dedicated function, named
MX_NVIC_Init, defined in the main.c. Moreover, the HAL_NVIC functions for each
peripheral are called in the order specified in the Code generation view bottom part
(see Figure 108).
As an example, the configuration shown in Figure 108 generates the following code:
/** NVIC Configuration
*/
void MX_NVIC_Init(void)
{
/* CAN1_TX_IRQn interrupt configuration */
HAL_NVIC_SetPriority(CAN1_TX_IRQn, 2, 2);
HAL_NVIC_EnableIRQ(CAN1_TX_IRQn);
/* PVD_IRQn interrupt configuration */
HAL_NVIC_SetPriority(PVD_IRQn, 0, 0);
HAL_NVIC_EnableIRQ(PVD_IRQn);
/* FLASH_IRQn interrupt configuration */
HAL_NVIC_SetPriority(FLASH_IRQn, 0, 0);
HAL_NVIC_EnableIRQ(CAN1_IRQn);
/* RCC_IRQn interrupt configuration */
HAL_NVIC_SetPriority(RCC_IRQn, 0, 0);
HAL_NVIC_EnableIRQ(CAN1_IRQn);
/* ADC_IRQn interrupt configuration */
HAL_NVIC_SetPriority(ADC_IRQn, 0, 0);
HAL_NVIC_EnableIRQ(ADC_IRQn);
}
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 112). 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 another definition than
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 112). 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 4 bytes when the item size can
not 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 111.
/* Create the thread(s) */
/* definition and creation of defaultTask */
osThreadDef(defaultTask, StartDefaultTask, osPriorityNormal, 0, 128);
defaultTaskHandle = osThreadCreate(osThread(defaultTask), NULL);
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 113:
FreeRTOS - Configuring timers, mutexes and semaphores).
/* Create the semaphores(s) */
/* definition and creation of myBinarySem01 */
osSemaphoreDef(myBinarySem01);
myBinarySem01Handle = osSemaphoreCreate(osSemaphore(myBinarySem01), 1);
If satisfied with simulator results, the user can click the Import Settings button to import
simulator settings in the current configuration.
Clicking Restore Default restores STM32CubeMX default settings for the Simulator
Configuration.
Clicking Ok saves the changes done within the Simulator Configuration panel and saved
settings will be used next time the GFXSIMULATOR window will be reopened.
Multiplier selection
5.14.2 Recommendations
The Clock tree view is not the only entry for clock configuration.
1. Go first through the RCC pinout configuration in the Pinout view to enable the clocks
as needed: external clocks, master output clocks and Audio I2S input clock when
available (see Figure 121).
Figure 121. Clock tree configuration: enabling RTC, RCC Clock source
and outputs from Pinout view
2. Then go to the RCC configuration in the Configuration view. The settings defined
there for advanced configurations will be reflected in the clock tree view. The settings
defined in the clock tree view may change the settings in the RCC configuration (see
Figure 122).
Table 15. Voltage scaling versus power over-drive and HCLK frequency
Parameter STM32CubeMX panel Value
Table 16 gives the relations between power-over drive mode and HCLK frequency.
Scale 3
≤120 MHz
POD is disabled
Scale 2
120 to 144 MHz
POD can be either disabled or enabled
Scale 1 when POD is disabled
144 to 168 MHz
Scale 2 when POD is enabled
POD must be enabled
168 to 180 MHz Scale 1 (otherwise frequency range not
supported)
HSI High Speed Internal oscillator: enabled after reset, lower accuracy than HSE.
HSE High Speed External oscillator: requires an external clock circuit.
PLL Phase Locked Loop: used to multiply above clock sources.
LSI Low Speed Internal clock: low power clocks usually used for watchdog timers.
LSE Low Speed External clock: powered by an external clock.
SYSCLK System clock
HCLK Internal AHB clock frequency
FCLK Cortex free running clock
AHB Advanced High Performance Bus
APB1 Low speed Advanced Peripheral Bus
APB2 High speed Advanced Peripheral Bus
within the currently configured sequence. It ensures that only possible transitions are
proposed to the user when a new step is added.
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 127).
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. The Edit Step window opens (see
Figure 128).
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.
Figure 130. Enabling the transition checker option on an already configured sequence -
At least one transition invalid
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 132).
Importing pinout
Figure 133 illustrates the example of the ADC configuration in the Pinout view: clicking
Import Pinout in the Power Consumption Calculator view selects the ADC peripheral and
GPIO A (Figure 134).
The Import pinout button allows to automatically select the peripherals that have been
configured in the Pinout view.
The performance achieved thanks to the ART accelerator is equivalent to 0 wait state
program execution from Flash memory. In terms of power consumption, it is equivalent
to program execution from RAM. In addition, STM32CubeMX uses the same selection
choice to cover both settings, RAM and Flash with ART ON.
Clock Configuration
This operation sets the AHB bus frequency or the CPU frequency that will be used for
computing the microcontroller power consumption. When there is only one possible
choice, the frequencies are automatically configured.
The clock configuration drop-down list allows to configure the application clocks:
– The internal or external oscillator sources: MSI, HSI, LSI, HSE or LSE),
– The oscillator frequency,
– Other determining parameters: PLL ON, LSE Bypass, AHB prescaler value, LCD
with duty...
Peripherals
The peripheral list shows the peripherals available for the selected power mode. The
power consumption is given assuming that peripherals are only clocked (e.g. not in use
by a running program). Each peripheral can be enabled or disabled. Peripherals
individual power consumptions are displayed in a tooltip. An overall consumption due
to peripheral analog and digital parts is provided in the step Results area (see
Figure 139).
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).
This is the maximum pulse current that can be delivered exceptionally, for instance when
the application is switched on during the starting phase.
Figure 143. Current project configuration updated with new SMPS model
Figure 144. SMPS database management window with new model selected
Figure 145. SMPS transition checker and state diagram helper window
Refer to Section 5.4.2: Project menu for code generation and C project settings related
topics.
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 149, 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:
#define I2C1_Pin GPIO_PIN_6
#define I2C1_GPIO_Port GPIOB
#define I2C1B7_Pin GPIO_PIN_7
#define I2C1B7_GPIO_Port GPIOB
In order for the generated project to compile, define statements shall follow strict
naming conventions. They shall start with a letter or an underscore as well as the
corresponding label. In addition, they shall not include any special character such
as minus sign, parenthesis or brackets. Any special character within the label will
be automatically replaced by an underscore in the define name.
If the label contains character strings between “[]” or “()”, only the first string listed
is used for the define name. As an example, the label “LD6 [Blue Led]”
corresponds the following define statements:
#define LD6_Pin GPIO_PIN_15
#define LD6_GPIO_Port GPIOD
The define statements are used to configure the GPIOs in the generated
initialization code. In the following example, the initialization of the pins labeled
Audio_RST_Pin and LD4_Pin is done using the corresponding define statements:
/*Configure GPIO pins : LD4_Pin Audio_RST_Pin */
GPIO_InitStruct.Pin = LD4_Pin | Audio_RST_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_LOW;
HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);
4. Finally it generates a Projects folder that contains the toolchain specific files that match
the user project settings. Double-clicking the IDE specific project file launches the IDE
and loads the project ready to be edited, built and debugged.
The following tables shows the main differences between the three possible
STM32CubeMX project generation options: HAL-only, LL-only, and mix of HAL and LL code.
Table 18. LL versus HAL code generation: drivers included in STM32CubeMX projects
Project configuration
Mix of HAL and
and drivers to be HAL only LL only Comments
LL
included
Table 19. LL versus HAL code generation: STM32CubeMX generated header files
Generated header Mix of HAL and
HAL only LL only Comments
files LL
Table 21. LL versus HAL: STM32CubeMX generated functions and function calls
Generated source
HAL only LL only Mix of HAL and LL Comments
files
Generated in
Generated in This function performs the
stm32xxx_hal_msp.c
Hal_msp_init() stm32xxx_hal_msp.c Not used peripheral resource
And called by
and called by HAL_init() configuration(1).
HAL_init()
Table 21. LL versus HAL: STM32CubeMX generated functions and function calls (continued)
Generated source
HAL only LL only Mix of HAL and LL Comments
files
[3]
Only HAL driver can
Generated in
be selected for the
HAL_<Peripheral>_Msp stm32xxx_hal_msp.c Peripheral resource
Not used <Peripheral>: function
Init() when HAL driver configuration(1)
generation and calls
selected for the
are done following [3]
<Peripheral>
[4]
Only HAL driver can
Generated in
be selected for the
HAL_<Peripheral>_Msp stm32xxx_hal_msp.c This function can be used to
Not used <Peripheral>: function
DeInit() when HAL driver free peripheral resources.
generation and calls
selected for the
are done following [4]
<Peripheral>
Figure 155. Project root folder with corresponding custom generated files
[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 158),
the stm32f4xx_hal_conf.h file in the project Inc folder (see Figure 159)
the project view within EWARM user interface as shown in Figure 160 and Figure 161.
Figure 160. New groups and new files added to groups in EWARM IDE
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 (see
Figure 167).
Optionally, remove the MCUs Selection bottom window by deselecting Window> Outputs
submenu (see Figure 168).
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 170).
c) You can also configure the RCC in order to use an external oscillator as potential
clock source (see Figure 171).
This completes the pinout configuration for this example.
Note: Starting with STM32CubeMX 4.2, the user can skip the pinout configuration by directly
loading ST Discovery board configuration from the Board selector tab.
2. Open the .pdf report using Adobe Reader or the .txt report using your favorite text
editor. The reports summarize all the settings and MCU configuration performed for the
project.
2. First select the clock source (HSE, HSI or PLLCLK) that will drive the system clock of
the microcontroller.
In the example taken for the tutorial, select HSI to use the internal 16 MHz clock (see
Figure 176).
To use an external clock source (HSE or LSE), the RCC peripheral shall be configured
in the Pinout view since pins will be used to connect the external clock crystals (see
Figure 177).
Other clock configuration options for the STM32F4DISCOVERY board would have
been:
– To select the external HSE source and enter 8 in the HSE input frequency box
since an 8 MHz crystal is connected on the discovery board:
– To select the external PLL clock source and the HSI or HSE as the PLL input clock
source.
3. Keep the core and peripheral clocks to 16 MHz using HSI, no PLL and no prescaling.
Note: Optionally, further adjust the system and peripheral clocks using PLL, prescalers and
multipliers:
Other clock sources independent from the system clock can be configured as follows:
– USB OTG FS, Random Number Generator and SDIO clocks are driven by an
independent output of the PLL.
– I2S peripherals come with their own internal clock (PLLI2S), alternatively derived
by an independent external clock source.
– USB OTG HS and Ethernet Clocks are derived from an external source.
4. Optionally, configure the prescaler for the Microcontroller Clock Output (MCO) pins that
allow to output two clocks to the external circuit.
5. Click to save the project.
6. Go to the Configuration tab to proceed with the project configuration.
b) With a 16 MHz APB clock (Clock tree view), set the prescaler to 16000 and the
counter period to 1000 to make the LED blink every millisecond.
4. Select the Configuration view. FatFs and USB buttons are then displayed.
5. FatFs and USB using default settings are already marked as configured . Click
FatFs and USB buttons to display default configuration settings. You can also change
them by following the guidelines provided at the bottom of the window.
3. Select the Code Generator tab to choose various C code generation options:
– The library files copied to Projects folder.
– C code regeneration (e.g. what is kept or backed up during C code regeneration).
– HAL specific action (e.g. set all free pins as analog I/Os to reduce MCU power
consumption).
In the tutorial example, select the settings as displayed in the figure below 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.
5. Once the connection is functional, click to generate the C code. The C code
generation process starts and progress is displayed as illustrated in the next figures.
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 8.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 Settings 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. Leave the option Initialize all peripherals with their default mode unchecked 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 214). The Pinout view is
loaded, matching the MCU pinout configuration on the evaluation board (see
Figure 215).
7. From the Peripheral tree on the left, expand the SDIO peripheral and select the SD 4
bits wide bus (see Figure 216).
8. Under the Middlewares category, check SD Card as FatFs mode (see Figure 217).
b) Configure the clock tree from the clock tab (see Figure 219).
10. In the Project Settings menu, specify the project name and destination folder. Then,
select the EWARM IDE toolchain.
11. Click Ok. Then, on the toolbar menu, click to generate the project.
12. Upon code generation completion, click Open Project in the Code Generation dialog
window (see Figure 221). This opens the project directly in the IDE.
13. 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. Adjust the heap and stack sizes (see
Figure 222).
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.
14. Go to the Application/User folder. Double-click the main.c file and edit it.
15. 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 (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.
16. For use case implementation, update main.c with the following code:
a) Insert main.c private variables in a dedicated user code section:
/* USER CODE BEGIN PV */
/* Private variables ------------------------------------------*/
FATFS SDFatFs; /* File system object for SD card logical drive */
FIL MyFile; /* File object */
const char wtext[] = "Hello World!";
const uint8_t image1_bmp[] = {
0x42,0x4d,0x36,0x84,0x03,0x00,0x00,0x00,0x00,0x00,0x36,0x00,0x00,0x00,
0x28,0x00,0x00,0x00,0x40,0x01,0x00,0x00,0xf0,0x00,0x00,0x00,0x01,0x00,
0x18,0x00,0x00,0x00,0x00,0x00,0x00,0x84,0x03,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x29,0x74,
0x51,0x0e,0x63,0x30,0x04,0x4c,0x1d,0x0f,0x56,0x25,0x11,0x79,0x41,0x1f,
0x85,0x6f,0x25,0x79,0x7e,0x27,0x72,0x72,0x0b,0x50,0x43,0x00,0x44,0x15,
0x00,0x4b,0x0f,0x00,0x4a,0x15,0x07,0x50,0x16,0x03,0x54,0x22,0x23,0x70,
0x65,0x30,0x82,0x6d,0x0f,0x6c,0x3e,0x22,0x80,0x5d,0x23,0x8b,0x5b,0x26};
/* USER CODE END PV */
b) Insert main functional local variables:
int main(void)
{
/* MCU Configuration----------------------------------------*/
MX_FATFS_Init();
/* Infinite loop */
/* USER CODE BEGIN WHILE */
while (1)
5. Enable the Transition checker to ensure the sequence is valid (see Figure 224). 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 224.
– By default the steps last 1 ms each, except for the wakeup transitions that are
preset using the transition times specified in the product datasheet (see
Figure 225).
– Some peripherals for which consumption is unavailable or negligible are
highlighted with ‘*’ (see Figure 225).
Step 1 (Run)
Findings
All peripherals are enabled although the application requires only the RTC.
Actions
– Lower the operating frequency.
– Enable solely the RTC peripheral.
– To reduce the average current consumption, reduce the time spent in this mode.
Results
The current is reduced from 9.05 mA to 2.16 mA (see Figure 227).
See Figure 233 for the sequence overall results: 7 ms duration, about 2 month 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 236).
3. Select the Asynchronous mode for the USART2 peripheral (see Figure 237).
4. Check that the signals are properly assigned on pins (see Figure 238):
– SYS_SWDIO on PA13
– TCK on PA14
– USART_TX on PA2
– USART_RX on PA3
11.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 239).
3. Click TIM2 and change the prescaler to 16000, the Word Length to 8 bits and the
Counter Period to 1000 (see Figure 241).
4. Enable TIM2 global interrupt from the NVIC Settings tab (see Figure 242).
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 246).
3. The Tera Term window displays a message coming from the board at a period of a few
seconds (see Figure 247).
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 249 and Figure 250).
If needed, modify the search criteria and the filter options and restart the search
process by clicking the Search button.
The row color shading and the Comments column indicate the level of matching:
– Bright green indicates an exact match: the MCU is fully compatible with the current
project (see Figure 250 for an example).
– Light green indicates a 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 249
for an example).
– Yellow indicates a 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 250 for an example).
Figure 250. 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 253. 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.
6. The current software component selection can also be kept for next projects:
a) Right-click the pack name and select Add pack into preferred pack list. It can be
removed later by clicking Remove pack from preferred pack list (see
Figure 254).
This way, the next time a project is created, the packs that correspond to a given
selection of software components will be automatically proposed under
Additional software.
8. Select Project, then Project settings to specify project parameters (see Figure 256),
and choose IAR™ EWARM as IDE.
This tutorial demonstrates how to achieve a functional project using the BlueNRG-MS
software pack.
Below the prerequisites to run this tutorial:
Hardware: NUCLEO-L053R8, X-NUCLEO-IDB05A1 and mini-USB cable (see
Figure 258)
Tools: STM32CubeMX, IDE (Atollic or any other toolchain supported by
STM32CubeMX)
Embedded software package: STM32CubeL0 (version 1.10.0 or higher), BlueNRG-MS
1.0.0 (see Figure 259).
Mobile application (see Figure 260): STMicroelectronics BlueNRG application for iOS
or Android
e) Answer No when prompted to initialize all peripherals in their default mode (see
Figure 263).
Select the Basic variant for the HCI_TL component. The Basic variant provides
the STMicroelectronics implementation of the HCI_TL API while the template
option requires the user to implement his own code.
Select the UserBoard variant as HCI_TL_INTERFACE component. Using the
UserBoard option generates the <boardname>_bus.c file, that is
nucleo_l053r8_bus.c for this tutorial, while the template option generates the
custom_bus.c file and requires the user to provide his own implementation.
Refer to the BlueNRG-MS pack documentation for more details on software
components.
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 265):
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.
Click Apply and check that the icon turns to . Click OK to close the
Configuration window.
9. Build and Run the SensorDemo application from the Atollic TrueStudio:
a) Configure the project properties (see Figure 273)
From the Project explorer panel, right-click the project name (SensorDemo) and
select Properties to open the Properties window.
Select C/C++ Build and enable parallel build from the Behavior tab to speed the
build process up.
b) Click the build icon, , to build the project.
c) Connect your computer to the Nucleo board ST-link connector via the USB cable.
d) Click from the Run menu to run the project on the board.
10. Test the STM32 SensorDemo application by launching the BlueNRG application on the
phone:
e) Scan for nearby devices.
f) Select the BlueNRG device.
g) Since there is no MEMs sensing elements on the hardware, press the Blue
Button to simulate MEMs data: the ST cube rotates by a fixed value each time the
button is pressed (see Figure 274).
Note: STM32CubeMX user interface is not accessible when the GUIBuilder tool is open.
4. Complete the GUI design work using GUIBuilder user interface and click File > Save to
generate the corresponding C file, respectively WindowDLG.c for Window type,
FramewinDLG.c for WindowFrame type.
5. Close GUIBuilder to return to STM32CubeMX user interface.
Click GFXSIMULATOR from the configuration view to open the Graphics simulator user
interface (see Figure 282).
1. Check in the top panel the Simulator’s current working assumptions and the mandatory
configuration settings, e.g. if LTDC is not enabled, some results will show as NA (not
available). See Figure 283.
2. Adjust the simulator parameter values from the left center panel, compare to current
configuration settings in the right panel (see Figure 284).
3. Check in the bottom panel the results for a set of supported use cases.
4. Optionally, click Import Settings to update current project configuration with simulator
settings to reach same performance results.
– A confirmation message pops up.
– When relevant, a warning message pops up with the settings that could not be
imported (unused peripherals, out of range clock frequency value,...).
5. Close the Graphics simulator window to go back to STM32CubeMX configuration view.
17 FAQ
17.3 Why are some pins highlighted in yellow or in light green in
the Chip view? Why cannot I change the function of some
pins (when I click some pins, nothing happens)?
These pins are specific pins (such as power supply or BOOT) which are not available as
peripheral signals.
17.4 Why do I get the error “Java 7 update 45” when installing
“Java 7 update 45” or a more recent version of the JRE?
The problem generally occurs on 64-bit Windows operating system, when several versions
of Java™ are installed on your computer and the 64-bit Java™ installation is too old.
During STM32CubeMX installation, the computer searches for a 64-bit installation of
Java™.
If one is found, the ‘Java 7 update 45’ minimum version prerequisite is checked. If the
installed version is older, an error is displayed to request the upgrade.
If no 64-bit installation is found, STM32CubeMX searches for a 32-bit installation. If one
is found and the version is too old, the ‘Java 7 update 45’ error is displayed. The user
must update the installation to solve the issue.
To avoid this issue from occurring, it is recommended to perform one of the following
actions:
1. Remove all Java™ installations and reinstall only one version (32 or 64 bits) (Java 7
update 45 or more recent).
2. Keep 32-bit and 64-bit installations but make sure that the 64-bit version is at least
Java 7 update 45.
Note: Some users (Java developers for example) may need to check the PC environment
variables defining hard-coded Java paths (e.g. JAVA_HOME or PATH) and update them so
that they point to the latest Java installation.
On Windows 7 you can check the Java installation using the Control Panel. To do this,
double-click the icon from Control Panel\All Control Panel to open the Java™
settings window (see Figure 285).
You can also enter ‘java –version’ as an MS-DOS command to check the version of your
latest Java installation (the Java program called here is a copy of the program installed
under C:\Windows\System32):
java version “1.7.0_45“
Java (TM) SE Runtime Environment (build 1.7.0_45-b18)
Java HotSpot (TM) 64-Bit Server VM (build 24.45-b08, mixed mode)
17.5 Why does the RTC multiplexer remain inactive on the Clock
tree view?
To enable the RTC multiplexer, the user shall enable the RTC peripheral in the Pinout view
as indicated below.
17.6 How can I select LSE and HSE as clock source and
change the frequency?
The LSE and HSE clocks become active once the RCC is configured as such in the Pinout
view. See Figure 287 for an example.
The clock source frequency can then be edited and the external source selected, see
Figure 288.
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 291 and Figure 292).
Figure 295. 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 296).
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 298).
Unchecking allows STM32CubeMX shifting blocks around
and freeing a block for the Ethernet MII mode. (see Figure 299).
hi2s2.Init.DataFormat = I2S_DATAFORMAT_16B;
hi2s2.Init.MCLKOutput = I2S_MCLKOUTPUT_DISABLE;
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 300).
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 kilobytes 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 302).
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 306: 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 307: Enabling the TouchSensing
peripheral, Figure 308: Touch-sensing sensor selection panel and Figure 309:
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 contents can be modified by the user
through STM32CubeMX user interface and/or using user sections in the code itself:
pdm2pcm.h/.c
B.3.11 Graphics
STMicroelectronics has selected the STemWin framework for the STM32 portfolio, see the
dedicated tutorial sections on how to create projects for this framework using
STM32CubeMX.
The generated projects follow the embedded software architecture shown in Figure 310 with
a hardware initialization file and a wrapper file to address the graphical stack specificity.
*UDSKLFDODSSOLFDWLRQ
67HP:LQ
:UDSSLQJILOH
+:B,QLWFK
069
The graphical stack comes with a specific UI designer tool that can be called from
STM32CubeMX user interface to perform advanced design work:
GUIBuilder for STemWin framework
All C, C++ or other files generated through the tool end up in the STM32CubeMX project
folder.
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 311 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/ wakeup/ 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 (wakeup 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 Wakeup 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 312). This set
of components is highly portable across the STM32 Series. The packages are fully
compatible with STM32CubeMX generated C code.
(YDOXDWLRQERDUGGHPRQVWUDWLRQ
'LVFRYHU\ERDUGGHPRQVWUDWLRQ 'HGLFDWHGERDUGGHPRQVWUDWLRQ
'HPREXLOGHUIUDPHZRUN
$SSOLFDWLRQOHYHOGHPRQVWUDWLRQV
0LGGOHZDUHH[DPSOHV
WLPHVWULQJILOH
8WLOLWLHV
(QKDQFHG
7&3,3 86% *UDSKLFDO )$7ILOH
1$1'
,Z,3VWDFN +RVW OLEUDU\ V\VWHP
PHPRU\
3RODU66/ 'HYLFHOLEUDU\ 67(P:LQ )DW)V
)UHH5726
GULYHU
5726
0LGGOHZDUHOHYHO
&06,6
+$/H[DPSOHV
(YDOXDWLRQERDUGVGLVFRYHU\ERDUGV
0&86HULHV670))))
GHGLFDWHGGHPRQVWUDWLRQERDUGV
+DUGZDUH
06Y9
18 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
acknowledgement.
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. 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.