UM1718
UM1718
UM1718
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 1) 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 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), STM32G0 (UM2303), STM32G4 (UM2570), STM32H7 (UM2217),
STM32L0 (UM1749), STM32L1 (UM1816), STM32L4/L4+ (UM1884), STM32MP1
(https://wiki.st.com/stm32mpu) and STM32WB (UM2442).
Contents
1 STM32Cube overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
20 FAQ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 300
20.1 On the Pinout configuration panel, why does STM32CubeMX
move some functions when I add a new peripheral mode? . . . . . . . . . . 300
20.2 How can I manually force a function remapping? . . . . . . . . . . . . . . . . . 300
20.3 Why are some pins highlighted in yellow or in light green in
the Pinout view? Why cannot I change the function of some
pins (when I click some pins, nothing happens)? . . . . . . . . . . . . . . . . . . 300
20.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? . . . . . . . . . . . 300
20.5 Why does the RTC multiplexer remain inactive on the Clock tree view? 301
20.6 How can I select LSE and HSE as clock source and
change the frequency? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 302
20.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? . . . . . . . . . . . . . . . . . . . . . . . . . . . . 302
20.8 Ethernet Configuration: why cannot I specify DP83848
or LAN8742A in some cases? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 303
List of tables
List of figures
1 STM32Cube overview
a. Arm is a registered trademark of Arm Limited (or its subsidiaries) in the US and/or elsewhere.
2.1 Principles
Customers need to quickly identify the MCU that best meets their requirements (core
architecture, features, memory size, performance…). While board designers main concerns
are to optimize the microcontroller pin configuration for their board layout and to fulfill the
application requirements (choice of peripherals operating modes), embedded system
developers are more interested in developing new applications for a specific target device,
and migrating existing designs to different microcontrollers.
The time taken to migrate to new platforms and update the C code to new firmware drivers
adds unnecessary delays to the project. STM32CubeMX was developed within STM32Cube
initiative which purpose is to meet customer key requirements to maximize software reuse
and minimize the time to create the target system:
• Software reuse and application design portability are achieved through STM32Cube
firmware solution proposing a common Hardware Abstraction Layer API across STM32
portfolio.
• Optimized migration time is achieved thanks to STM32CubeMX built-in knowledge of
STM32 microcontrollers, peripherals and middleware (LwIP and USB communication
protocol stacks, FatFs file system for small embedded systems, FreeRTOS).
STM32CubeMX graphical interface performs the following functions:
• Fast and easy configuration of the MCU pins, clock tree and operating modes for the
selected peripherals and middleware
• Generation of pin configuration report for board designers
• Generation of a complete project with all the necessary libraries and initialization C
code to set up the device in the user defined operating mode. The project can be
directly open in the selected application development environment (for a selection of
supported IDEs) to proceed with application development (see Figure 1).
During the configuration process, STM32CubeMX detects conflicts and invalid settings and
highlights them through meaningful icons and useful tool tips.
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.
• Graphics simulator
For graphics-capable microcontrollers, STM32CubeMX allows the user to simulate a
graphics configuration and adjust 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.
Several proxy types exist and different computer network configurations are possible:
• Without proxy: the application directly accesses the web (Windows default
configuration).
• Proxy without login/password
• Proxy with login/password: when using an Internet browser, a dialog box opens and
prompts the user to enter its login/password.
• Web proxies with login/password: when using an Internet browser, a web page opens
and prompts the user to enter its login/password.
If needed, contact your IT administrator for proxy information (proxy type, http address,
port).
STM32CubeMX does not support web proxies. In this case, the user 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:
3. In the Connection Parameters tab, specify the proxy server settings appropriate for
your network configuration by selecting a proxy type among the following possibilities
(see Figure 7):
– No Proxy
– Use System Proxy Parameters
On Windows, proxy parameters will be retrieved from the PC system settings.
6. Select Help > Install New Libraries submenu to select among a list of possible
packages to install.
7. If the tool is configured for manual checks, select Help > Check for Updates to find out
about new tool versions or firmware library patches available to install.
2. Click From Local … button to browse the computer filesystem and select an
embedded software package. STM32Cube MCU packages come as zip archives and
embedded software packs come as .pack archives.
This action is required in the following cases:
– No Internet access is possible but the embedded software package is available
locally on the computer.
– The embedded software package is not public and hence not available on
Internet. For such packages, STM32CubeMX cannot detect and propose updates.
3. Click From URL… button to specify the download location from Internet for either one
of the pack .pdsc file or the vendor pack index (.pidx).
Proceed as follow:
a) Choose From URL … and click New (see Figure 10).
b) Specify the .pdsc file url. As an example, the url of Oryx-Embedded middleware
pack is https://www.oryx-embedded.com/download/pack/Oryx-
Embedded.Middleware.pdsc (see Figure 11).
c) Click the Check button to verify that the url provided is valid (see Figure 11).
d) Click OK. The pack pdsc information is now available in the user defined pack list
(see Figure 12).
To delete a url from the list, select the url checkbox and click Remove.
e) Click OK to close the window and start retrieving psdc information. Upon
successful completion, the available pack versions are shown in the list of libraries
that can be installed. Use the corresponding checkbox to select a given release.
f) Click Install Now to start downloading the software pack. A progress bar opens to
indicate the installation progress. If the pack comes with a license agreement, a
window pops up to ask for user’s acceptance (see Figure 14). When the
installation is successful, the check box turns green (see Figure 15).
The user will then be able to add software components from this pack to its
projects.
STM32CubeMX user interface comes with three main views the user can navigate through
using convenient breadcrumbs:
1. the Home page
2. the New project window
3. the project page
They come with panels, buttons and menus allowing users to take actions and make
configuration choices with a single click.
The user interface is detailed in the following sections.
For C code generation, although the user can switch back and forth between the different
configuration views, it is recommended to follow the sequence below:
1. From the Project Manager view, configure the project settings.
2. From the Mode panel in the Pinout & Configuration view, configure the RCC
peripheral by enabling the external clocks, master output clocks, audio input clocks
(when relevant for your application). This automatically displays more options on the
Clock configuration view (see Figure 86). Then, select the features (peripherals,
middlewares) and their operating modes relevant to the application.
3. If necessary, adjust the clock tree configuration from the clock configuration view.
4. From the Configuration panel in the Pinout & Configuration view configure the
parameters required to initialize the peripherals and middleware operating modes.
5. Generate the initialization C code by clicking .
1. On New project: to avoid any popup error messages at this stage, make sure an Internet connection is available
(Connection Parameters tab under Help > Updater settings menu) or that Data Auto-refresh settings are set to No
Auto-Refresh at application start (Updater Settings tab under Help > Updater Settings menu).
2. On Import, a status window displays the warnings or errors detected when checking for import conflicts. The user can then
decide to cancel the import.
Caution: On project load: STM32CubeMX detects if the project was created with an older version of
the tool and if this is the case, it proposes the user to either migrate to use the latest
STM32CubeMX database and STM32Cube firmware version, or to continue.
Prior to STM32CubeMX 4.17, clicking Continue still upgrades to the latest database
“compatible” with the SMT32Cube firmware version used by the project.
Starting from STM32CubeMX 4.17, clicking Continue keeps the database used to create the
project untouched. If the required database version is not available on the computer, it will
be automatically downloaded.
When upgrading to a new version of STM32CubeMX, make sure to always backup your
projects before loading the new project (especially when the project includes user code).
Help
Opens the STM32CubeMX user manual. None
F1
About
Shows version information. None
Alt-A
Docs & Resources Displays the official documentation available for
None
Alt-D the MCU used in the current project.
Opens a dialog window that proposes to refresh
STM32CubeMX database with STM32 MCU latest
Refresh Data
information (description and list of official None
Alt-R
documents), and allows the user to download of
all official documentation in one shot.
Check for Updates Shows the software and firmware release updates
Click
Alt-C available for download.
Shows all the embedded software packages
available for installation.
Manage embedded
A green check box indicates that the package is
software packages Click
already installed in the user repository folder (the
Alt-U
repository folder location is specified under
Help > Updater Settings menu).
Opens the updater settings window to configure
manual versus automatic updates, proxy settings
Updater Settings…
for Internet connections, repository folder where None
Alt-S
the downloaded software and firmware releases
will be stored.
Opens the user preference window to enable or
User Preferences None
disable collect of features usage statistics.
The main purpose here is to select from the STM32 portfolio a microcontroller or board part
number that best fits the user application needs.
This window shows two tabs to choose from:
• the MCU selector tab (offering a list of target processors)
• a Board selector tab (showing a list of STMicroelectronics boards)
• A Cross selector tab (allow the user to find, for a given MCU/MPU part number and for
a set of criteria, the best replacement within the STM32 portfolio).
Figure 28. New Project window - MCU list with close function
Note: A matching percentage is computed for each user selected criteria, for example:
- when requesting four instances of the CAN peripheral, 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.
Clicking “ACCESS TO CROSS SELECTOR” under the “Start my project from Cross
Selector” section of the main page opens the New Project window on the Cross selector tab.
Two drop downs menus allow the user to select the vendor and the part number of the
product to be compared to (see Figure 32). A part number can also be entered partially:
STM32CubeMX proposes a list of matching products (see Figure 33).
Compare cart
Once a part number is selected, a list of matching ST part number candidates is displayed
along with their matching ratio in the Matching ST candidates panel.
By default, the three closest matches are selected and added to the compare cart along with
the part number to be compared to (see Figure 34).
Buttons are available to manipulate and save a copy of the compare cart view:
• to hide criteria that are not used for the comparison or show all criteria.
• to come back to default STM32CubeMX comparison settings
• to copy and paste the current cart view in a document or email.
Figure 35. Cross selector - Part number selection for a new project
Clicking the Cross Selector Tab allows the user to go back to the cart and change the
current selection for another part number.
locations:
• to the home page by clicking the Home breadcrumb
• to the new project window by clicking the part number
• back to the project page by clicking the project name (or Untitled if the project does not
have a name yet).
Selecting a board, then answering No in the dialog window requesting to initialize all
peripherals to their default mode, automatically sets the pinout for this board. However, only
the pins set as GPIOs are marked as configured, i.e. highlighted in green, while no
peripheral mode is set. The user can then manually select from the peripheral tree the
peripheral modes required for its application (see Figure 37).
Figure 37. STM32CubeMX Main window upon board selection (peripherals not initialized)
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 38).
buttons allow opening the configuration options for the given component (Mode and
Configuration panels). The button icon color reflects the status of the configuration
status.
• An Additional Software function that allows to select, for the current project, software
components that are not available by default. Selecting an additional software
component will update the Pinout & Configuration view accordingly.
• A Pinout menu that allows to perform pinout related actions such as clear pinout
configuration, export pinout configuration as csv file, etc...
Tips
• You can re-dimension the different panels at will: hovering the mouse over a panel
border display a two-ended arrow: right-click and pull in a direction to either extend or
reduce the panel.
• You can show/hide the Configuration, Mode, Pinout and System views using the
open and close arrows.
Contextual help
The Contextual Help window is displayed when hovering the mouse over a peripheral or a
middleware short name.
By default, the window displays the extended name and source of configuration conflicts if
any (see Figure 39).
Clicking the details and documentation link (or CTRL+d) provides additional information
such as summary and reference documentation links (see Figure 40). 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.
FatFs code without a predefined peripheral mode. Then, it will be up to the user to connect
the middleware with a user-defined peripheral by updating the generated user_diskio.c/.h
driver files with the necessary code.
The Pinout view is automatically refreshed to match the user’s component configuration
performed in the Mode panel.
Assigning pins directly through the Pinout view instead of the Mode panel requires a good
knowledge of the MCU since each individual pin can be assigned to a specific function.
Provides a list of MCUs that best match the pin configuration of the
current project. The matching can be:
– An exact match
– A partial match with hardware compatibility: pin locations are the
List Pinout Compatible MCUs Alt-L same, pin names may have been changed
– A partial match without hardware compatibility: all signals could be
mapped but not all at the same pin location
Refer to Section 14: Tutorial 5: Exporting current project configuration
to a compatible MCU.
Export pinout Generates pin configuration as a .csv text file including alternate
-
with Alt. Functions functions information.
Export pinout Generates pin configuration as a .csv text file excluding alternate
Ctrl-U
without Alt. Functions functions information.
Opens a window to specify the number of GPIOs to be freed among
Reset used GPIOs Alt-G
the total number of GPIO pins that are configured.
Opens a window to specify the number of GPIOs to be configured
among the total number of GPIO pins that are not used yet.
Specify their mode: Input, Output or Analog (recommended
Set unused GPIOs Ctrl-G configuration to optimize power consumption).
Caution: Before using this menu, make sure the debug pins
(available under SYS peripheral) are set to access
microcontroller debug facilities.
Layout reset - -
This Search field allows the user to search for a pin name, signal name
or signal label in the Pinout view.
- When it is found, the pin or set of pins that matches the search criteria
blinks on the Pinout view.
Click the Pinout view to stop blinking.
Tip
If a mode becomes unavailable (highlighted in fuchsia), try to find another pin remapping
configuration for this mode by following the steps below:
1. From the Pinout view, deselect the assigned functions one by one until the mode
becomes available again.
2. Then, select the mode again and continue the pinout configuration with the new
sequence (see Appendix A: STM32CubeMX pin assignment rules for a remapping
example). This operation being time consuming, it is recommended to deselect the
Keep Current Signals Placement checkbox.
Note: Even if Keep Current Signals Placement is unchecked, GPIO_ functions (excepted
GPIO_EXTI functions) are not moved by STM32CubeMX.
Configuration is invalid and needs to be fixed for the generated C project to be functional.
GPIO, DMA and NVIC settings can be accessed either via a dedicated button (like other
peripherals or via a tab in the Configuration panel (see Figure 46).
Figure 46. Configuration window tabs (GPIO, DMA and NVIC settings for STM32F4 Series)
Tooltip
Guides the user through the settings of
parameters with valid min-max range.
To display it, move the mouse over a
parameter value from a list of possible
values.
Search
No check option
By default, STM32CubeMX checks that the parameter values entered by the user are valid.
You can bypass this check by selecting the option No Check for a given parameter. This
allows entering you any value (such as a constant) that might not be known by
STM32CubeMX configuration.
The validity check can be bypassed only on parameters whose values are of integer type
(either hexadecimal or decimal). It cannot be bypassed on parameters coming from a
predefined list of possible values or on those which are of non-integer or text type.
To go back to the default mode (decimal or hexadecimal values with validity check enabled),
enter a decimal or hexadecimal value and check the relevant option (hexadecimal or
decimal check).
Caution: When a parameter depends upon another parameter that is set to No Check:
• Case of a parameter depending on another parameter for the evaluation of its minimum
or maximum possible value: If the other parameter is set to No Check, the minimum or
maximum value is no longer evaluated and checked.
• Case of a parameter depending on another parameter for the evaluation of its current
value: If the other parameter is set to No Check, the value is no longer automatically
derived. Instead, it is replaced with the formula text showing as variable the string of
the parameter set to No check (see Figure 48).
• 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 54).
Click on a row or select a set of rows to display the corresponding GPIO parameters:
• GPIO PIN state
It changes the default value of the GPIO Output level. It is set to low by default and can
be changed to high.
• GPIO mode (analog, input, output, alternate function)
Selecting a peripheral mode in the Pinout view automatically configures the pins with
the relevant alternate function and GPIO mode.
• GPIO pull-up/pull-down
It is set to a default value and can be configured when other choices are possible.
• GPIO maximum output speed (for communication peripherals only)
It is set to Low by default for power consumption optimization and can be changed to a
higher frequency to fit application requirements.
• User Label
It changes the default name (e.g. GPIO_input) into a user defined name. The Pinout
view is updated accordingly. The GPIO can be found under this new name via the Find
menu.
The Group by Peripherals checkbox allows the user to group all instances of a peripheral
under the same window (see Figure 59).
As shown in Figure 60, 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 62). 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 to a destination memory.
Peripheral dedicated interrupts can also be accessed through the NVIC window in the
Peripheral Configuration window (see Figure 66).
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
GPIO_InitStruct.Alternate = GPIO_AF9_CAN1;
HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);
For some peripherals, the application still needs to call another function to actually
activate the interruptions. Taking the timer peripheral as an example, the
HAL_TIM_IC_Start_IT function needs to be called to start the Timer input capture (IC)
measurement in interrupt mode.
• Configuration of interrupts initialization sequence
Checking Select for Init sequence ordering for a set of peripherals moves the
HAL_NVIC function calls for each peripheral to a same dedicated function, named
MX_NVIC_Init, defined in the main.c. Moreover, the HAL_NVIC functions for each
peripheral are called in the order specified in the Code generation view bottom part
(see Figure 68).
As an example, the configuration shown in Figure 68 generates the following code:
/** NVIC Configuration
*/
void MX_NVIC_Init(void)
{
/* CAN1_TX_IRQn interrupt configuration */
HAL_NVIC_SetPriority(CAN1_TX_IRQn, 2, 2);
HAL_NVIC_EnableIRQ(CAN1_TX_IRQn);
/* PVD_IRQn interrupt configuration */
HAL_NVIC_SetPriority(PVD_IRQn, 0, 0);
HAL_NVIC_EnableIRQ(PVD_IRQn);
/* FLASH_IRQn interrupt configuration */
HAL_NVIC_SetPriority(FLASH_IRQn, 0, 0);
HAL_NVIC_EnableIRQ(CAN1_IRQn);
/* RCC_IRQn interrupt configuration */
HAL_NVIC_SetPriority(RCC_IRQn, 0, 0);
HAL_NVIC_EnableIRQ(CAN1_IRQn);
/* ADC_IRQn interrupt configuration */
HAL_NVIC_SetPriority(ADC_IRQn, 0, 0);
HAL_NVIC_EnableIRQ(ADC_IRQn);
}
• Interrupts handler code generation
By default, STM32CubeMX generates interrupt handlers within the stm32xxx_it.c file.
As an example:
void NMI_Handler(void)
{
HAL_RCC_NMI_IRQHandler();
}
void CAN1_TX_IRQHandler(void)
{
HAL_CAN_IRQHandler(&hcan1);
}
The column Generate IRQ Handler allows controlling whether the interrupt handler
function call shall be generated or not. Deselecting CAN1_TX and NMI interrupts from
the Generate IRQ Handler column as shown in Figure 68 removes the code
mentioned earlier from the stm32xxx_it.c file.
• Tasks
Under the Tasks section, click the Add button to open the New Task window where
task name, priority, stack size and entry function can be configured (see Figure 71).
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 71). 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 70.
/* Create the thread(s) */
/* definition and creation of defaultTask */
osThreadDef(defaultTask, StartDefaultTask, osPriorityNormal, 0, 128);
defaultTaskHandle = osThreadCreate(osThread(defaultTask), NULL);
Under each object dedicated section, clicking the Add button to open the corresponding
New <object> window where the object specific parameters can be specified. Object
settings can be modified at any time: double- clicking the relevant row opens again the New
<object> window for edition.
Note: Expand the window if the newly created objects are not visible.
• Timers
Prior to creating timers, their usage (USE_TIMERS definition) must be enabled in the
software timer definitions section of the Configuration parameters tab. In the
same section, timer task priority, queue length and stack depth can be also configured.
The timer can be created to be one-shot (run once) or auto-reload (periodic). The timer
name and the corresponding callback function name must be specified. It is up to the
user to fill the callback function code and to specify the timer period (time between the
timer being started and its callback function being executed) when calling the CMSIS-
RTOS osTimerStart function.
• Mutexes / Semaphores
Prior to creating mutexes, recursive mutexes and counting semaphores, their usage
(USE_ MUTEXES, USE_RECURSIVE_MUTEXES,
USE_COUNTING_SEMAPHORES definitions) must be enabled within the Kernel
settings section of the Configuration parameters tab.
The following code snippet shows the generated code corresponding to Figure 72).
When used as timebase source, a given peripheral is grayed and can no longer be selected
(see Figure 77).
As illustrated in the following examples, the selection of the HAL timebase source and the
use of FreeRTOS influence the generated code.
Figure 78. NVIC settings when using SysTick as HAL timebase, no FreeRTOS
Interrupt priorities (in main.c) and handler code (in stm32f4xx_it.c) are generated
accordingly:
• main.c file
/* SysTick_IRQn interrupt configuration */
HAL_NVIC_SetPriority(SysTick_IRQn, 0, 0);
• stm32f4xx_it.c file
/**
* @brief This function handles System tick timer.
*/
void SysTick_Handler(void)
{
/* USER CODE BEGIN SysTick_IRQn 0 */
/* USER CODE END SysTick_IRQn 0 */
HAL_IncTick();
HAL_SYSTICK_IRQHandler();
/* USER CODE BEGIN SysTick_IRQn 1 */
Figure 79. NVIC settings when using FreeRTOS and SysTick as HAL timebase
As shown in the code snippets below, the SysTick interrupt handler is updated to use
CMSIS-os osSystickHandler function.
• main.c file
/* SysTick_IRQn interrupt configuration */
HAL_NVIC_SetPriority(SysTick_IRQn, 15, 0);
• stm32f4xx_it.c file
/**
* @brief This function handles System tick timer.
*/
void SysTick_Handler(void)
{
/* USER CODE BEGIN SysTick_IRQn 0 */
Figure 80. NVIC settings when using FreeRTOS and TIM2 as HAL timebase
When a peripheral is set as boot device, it imposes a specific pinout: some signals have to
be mapped exclusively on pins visible by the boot ROM and only these signals/pins will be
taken into account by the boot ROM program.
When a functional mode of a ROM-bootable peripheral is set, the pinout linked to this mode
is the same of that for a runtime context except for the signals imposed on specific pins by
the boot ROM code.
During the boot step (boot ROM code execution), the peripheral is running only with the
sub-set of bootable signals and pins. After boot, during runtime, the peripheral runs with all
signals necessary to the selected functional mode.
For GPIOs (see Figure 85), assignment is done through the Pinout view directly or later and
automatically through its selection in the platform settings panel of a middleware.
Actual clock speeds are displayed and active. The use clock signals are highlighted in blue.
Reverse path is supported: just enter the required clock speed in the blue filed and
STM32CubeMX will attempt to reconfigure multipliers and dividers to provide the requested
value. The resulting clock value can then be locked by right clicking the field to prevent
modifications.
STM32CubeMX generates the corresponding initialization code:
• main.c with relevant HAL_RCC structure initializations and function calls
• stm32xxxx_hal_conf.h for oscillator frequencies and VDD values.
d) Finally, iterating through multiplier/dividers values to fix the issue. The clock tree is
cleared from fuchsia highlights if a solution is found. Otherwise an error message
is displayed.
Note: To be available from the clock tree, external clocks, I2S input clock, and master clocks shall
be enabled in RCC configuration in the Pinout view. This information is also available as
tooltips.
The tool will automatically perform the following operations:
• Adjust bus frequencies, timers, peripherals and master output clocks according to user
selection of clock sources, clock frequencies and prescalers/multipliers/dividers values.
• Check the validity of user settings.
• Highlight invalid settings in fuchsia and provide tooltips to guide the user to achieve a
valid configuration.
The Clock Configuration view is adjusted according to the RCC settings (configured in
RCC Pinout & Configuration views) and vice versa:
• If in RCC Pinout view, the external and output clocks are enabled, they become
configurable in the Clock Configuration view.
• If in RCC Configuration view, the Timer prescaler is enabled, the choice of Timer clocks
multipliers will be adjusted.
Conversely, the clock tree configuration may affect some RCC parameters in the
configuration view:
• Flash latency: number of wait states automatically derived from VDD voltage, HCLK
frequency, and power over-drive state.
• Power regulator voltage scale: automatically derived from HCLK frequency.
• Power over-drive is enabled automatically according to HCLK frequency. When the
power drive is enabled, the maximum possible frequency values for AHB and APB
domains are increased. They are displayed in the Clock Configuration view.
The default optimal system settings that is used at startup are defined in the
system_stm32f4xx.c file. This file is copied by STM32CubeMX from the STM32CubeF4
MCU package. The switch to user defined clock settings is done afterwards in the main
function.
Figure 86 gives an example of Clock tree configuration for an STM32F429x MCU and
Table 9 describes the widgets that can be used to configure each clock.
Multiplier selection
4.7.2 Recommendations
The Clock Configuration view is not the only entry for clock configuration, RCC and RTC
peripherals can also be configured.
1. From the Pinout & Configuration view, go to the RCC mode panel to enable the
clocks as needed: external clocks, master output clocks and Audio I2S input clock
when available. Then go to the RCC configuration panel, and adjust the default settings
if needed. Changes will be reflected in the Clock Configuration view. The defined
settings may change the settings in the RCC configuration as well (see Figure 88).
Figure 88. Clock tree configuration: enabling RTC, RCC clock source
and outputs from Pinout view
2. Go to the RCC configuration in the Pinout & Configuration view. The settings
defined there for advanced configurations will be reflected in the Clock configuration
view. The defined settings may change the settings in the RCC configuration.
Table 10. Voltage scaling versus power over-drive and HCLK frequency
Parameter STM32CubeMX panel Value
Table 11 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.
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.
Selecting Other Toolchains (GPDSC) generates a gpdsc file. The gpdsc file provides a
generic description of the project, including the list and paths of drivers and other files
(such as startup files) that are required for building the project. This allows extending
STM32CubeMX project generation to any toolchain supporting gpdsc since the
toolchain will be able to load a STM32CubeMX generated C project by processing the
gpdsc file information. To standardize the description of embedded projects, the gpdsc
solution is based on CMSIS-Pack.
• Additional project settings for SW4STM32 and Atollic® TrueSTUDIO® toolchain:
Select the optional Generate under root checkbox to generate the toolchain project
files in STM32CubeMX user project root folder or deselect it to generate them under a
dedicated toolchain folder.
STM32CubeMX project generation under the root folder allows to benefit from the
following Eclipse features when using Eclipse-based IDEs such as SW4STM32 and
TrueStudio®:
– Optional copy of the project into the Eclipse workspace when importing a project.
– Use of source control systems such as GIT or SVN from the Eclipse workspace.
However, it shall be noted that choosing to copy the project into workspace will prevent
any further synchronization between changes done in Eclipse and changes done in
STM32CubeMX as there will be two different copies of the project.
• Linker settings: value of minimum heap and stack sizes to be allocated for the
application. The default values proposed are 0x200 and 0x400 for heap and stack
sizes, respectively. These values may need to be increased when the application uses
middleware stacks.
• Firmware package selection when more than one version is available (this is the case
when successive versions implement the same API and support the same MCUs). By
default, the latest available version is used.
• Firmware location selection option
The default location is the location specified under the Help > updater settings menu.
Deselecting the Use Default Firmware Location checkbox allows the user to specify
a different path for the firmware that will be used for the project (see Figure 95).
The new location must contain at least a Drivers directory containing the HAL and
CMSIS drivers from the relevant STM32Cube MCU package. An error message pops
up if the folders cannot be found (see Figure 96).
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 97).
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.
Figure 100 shows the result of the template configuration shown on Figure 99: a sample.h
file is generated according to sample_h.ftl template definition.
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 101,
allows the generation of the function definition without the static keyword and hence extends
its visibility outside the current file (see Figure 102).
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 109 and Figure 110 and check the limitation(s) in available peripheral
modes.
Figure 109. Set unused GPIO pins with Keep Current Signals Placement checked
Figure 110. Set unused GPIO pins with Keep Current Signals Placement unchecked
Figure 111. Additional software components - collapsed view showing packs and bundles
Figure 112. Additional software components - expanded view showing component details
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 113 and Figure 114).
2. Clicking a proposed solution in the bottom panel highlights the software component
selection checkbox in the component table above (see Figure 115).
3. Selecting the recommended software component resolves the condition. The condition
status changes to resolved, , (see Figure 116).
The current selection of additional software components appears in the tree view (see
Figure 118).
5 STM32CubeMX tools
Adding a step
There are two ways to add a new step:
• Click Add in the Power Consumption panel. The New Step window opens with empty
step settings.
• Or, select a step from the sequence table and click Duplicate. A New Step window
opens duplicating the step settings (see Figure 123).
Once a step is configured, resulting current consumption and TAMAX values are provided in
the window.
Editing a step
To edit a step, double-click it in the sequence table, this will open the Edit Step window.
Moving a step
By default, a new step is added at the end of a sequence. Click the step in the sequence
table to select it and use the Up and Down buttons to move it elsewhere in the sequence.
Deleting a step
Select the step to be deleted and click the Delete button.
Using interpolation
For steps configured for active modes (Run, Sleep), frequency interpolation is supported by
selecting CPU frequency as User Defined and entering a frequency in Hz (see Figure 127).
Importing pinout
Figure 128 illustrates the example of the ADC configuration in the Pinout view: clicking
Enable IPs from Pinout in the Power Consumption Calculator view selects the ADC
peripheral and GPIO A (Figure 129).
The Enable IPs from Pinout button allows the user to automatically select the peripherals
that have been configured in the Pinout view.
The user can select the peripherals relevant for the application:
– None (Disable All),
– Some (using peripheral dedicated checkbox),
– All (Activate All),
– Or all from the previously defined pinout configuration (Import Pinout).
Only the selected and enabled peripherals are taken into account when computing the
power consumption.
• Step duration
The user can change the default step duration value. When building a sequence, the
user can either create steps according to the application actual power sequence or
define them as a percentage spent in each mode. For example, if an application
spends 30% in Run mode, 20% in Sleep and 50% in Stop, the user must configure a
3-step sequence consisting in 30 ms in Run, 20 ms in Sleep and 50 ms in Stop.
• Additional Consumption
This field allows entering an additional consumption resulting from specific user
configuration (e.g. MCU providing power supply to other connected devices).
Figure 138. Current project configuration updated with new SMPS model
Figure 139. SMPS database management window with new model selected
Figure 140. SMPS transition checker and state diagram helper window
The BLE mode can be selected from the left panel and configured to reflect the user’s
application relevant settings.
Clicking “Load Example N” loads the sequence corresponding to the example N (see
Figure 145).
The example can be changed anytime: the new sequence can be either added to the
current sequence, or replace it (see Figure 146).
Note: The examples are provided for a given part number and may require adjustments when
used for a different part number. Also, after loading, it is recommended to edit each step and
check settings.
DDR configuration is accessible like the other peripherals in the Pinout & Configuration
view: clicking the DDR from the component panel, opens the mode and configuration
panels.
DDR Test suite testing and tuning features are available from the Tools view.
The DDR suite relies on two important concepts:
• the DDR timings as key inputs for the configuration of the DDR Controller and PHY
• the tuning of DDR signals to compensate board design imperfections.
Another example: for a configuration with two “DDR3 16 bits 2 Gb” chips, settings are
“DDR3/DDR3L”, “32 bits” and 4 Gb”.
Note: Contexts for DDR IP cannot be changed, DDR is tied to “Cortex-A7 Non-Secure” identified
as “Cortex-A7 NS” in the tool.
DDR configuration
Clicking on a parameter will show additional details in the DDR configuration footer.
• The DDR frequency is taken from the ‘Clock configuration’ tab, it cannot be changed in
the DDR configuration.
• The ‘Relaxed Timing’ mode is used during bring-up phase for trying relaxed key DDR
timings value (one tCK added to tRC, tRCD and tRP timings)
• Other parameters must be retrieved from the user DDR datasheet.
• Some parameters are read-only: they are for information only and depend on the DDR
type.
Clicking “generate code” automatically computes the DDR node of the device tree (DDR
Controller and DDR PHY registers values) based on these parameters.
DDR3 configuration
For DDR3, the configuration is made easier with the selection of a Speed Bin / Grade
combination, instead of manually editing timing parameters.
The Speed Bin / Grade combination has to match the selected DDR. If the exact
combination is not in the pick-list, “1066E / 6-6-6” must be selected for faster DDR Speed
bin / Grade, whereas “1066G / 8-8-8” can be used as a relaxed configuration.
Timing edition is then optional and reserved for advanced users: select Show Advanced
parameters to display the list.
Prerequisites
• Installation of ST-Link USB driver to perform firmware upgrades: for Windows, latest
version of STSW-LINK009 must be used. For Linux, the STSW-LINK007 driver must
be used. Both can be downloaded from www.st.com.
• Installation of STM32CubeProgrammer (for SYSRAM loading only): installer can be
downloaded from www.st.com.
If U-Boot SPL loading in SysRAM is required, it can be performed through UART or USB
using the STM32CubeProgrammer tool. If not automatically detected by STM32CubeMX,
the STM32CubeProgrammer tool location must be specified in the Connection settings
window: click to open it. U-Boot SPL file has to be manually selected in the build image
folder.
Once up, the connection gives the various services and target information (see Figure 151).
Output/Log messages
STM32CubeMX outputs DDR suite related activity logs (see Figure 152) and interactive
protocol communication logs (see Figure 153). They are displayed by enabling outputs from
the Window menu.
This step is optional if the used U-Boot SPL already contains the required DDR
configuration. It trigs the DDR Controller and PHY initialization with those registers, and
allows the user to quickly test a configuration without generating the device tree and
dedicated U-Boot SPL binary file.
Tunable signals
The tunable signals are
• DQS signals: position for each data byte
• the 8 DQ bits: delay for each data byte.
Some DDR registers are dedicated to store the corresponding tuned settings:
• ‘Slave DDL Phase’, ‘DQS delay fine tuning’ and ‘DQS# delay fine tuning’ define the
position of the DQS strobe signal for a particular byte: this position is the best one
regarding DQ line eye diagram
• ‘DQ bit x lane delay fine tuning’ defines the delay to apply on bit x of particular byte to
compensate potential line length variation for this particular bit.
Note: It is recommended to perform tuning on several boards to make sure that the tuned
parameter variation is limited.
Tuning process
Tuning is done in three consecutive steps (see Figure 159):
1. DQS gating
2. Bit deskew
3. Eye training
Bit deskew
The Bit deskew panel (see Figure 160) gives a graphical representation of
• the best DQS signal position for the given byte in order to adjust DQ line delay
• the delay to apply for each DQ line of the considered byte. The unit delay value is
20.56 ps. There are four steps. Bit lane delay is thus tunable from 0 to 61.68 ps.
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 166, the code
generation produces the following code, keeping the I2C1 label on the original port
B pin 6 define statements and adding B7 suffix on pin 7 define statements:
In order for the generated project to compile, define statements shall follow strict
naming conventions. They shall start with a letter or an underscore as well as the
corresponding label. In addition, they shall not include any special character such
as minus sign, parenthesis or brackets. Any special character within the label will
be automatically replaced by an underscore in the define name.
If the label contains character strings between “[]” or “()”, only the first string listed
is used for the define name. As an example, the label “LD6 [Blue Led]”
corresponds the following define statements:
#define LD6_Pin GPIO_PIN_15
#define LD6_GPIO_Port GPIOD
The define statements are used to configure the GPIOs in the generated
initialization code. In the following example, the initialization of the pins labeled
Audio_RST_Pin and LD4_Pin is done using the corresponding define statements:
/*Configure GPIO pins : LD4_Pin Audio_RST_Pin */
GPIO_InitStruct.Pin = LD4_Pin | Audio_RST_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_LOW;
HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);
4. Finally it generates a Projects folder that contains the toolchain specific files that match
the user project settings. Double-clicking the IDE specific project file launches the IDE
and loads the project ready to be edited, built and debugged.
Table 15. LL versus HAL code generation: drivers included in STM32CubeMX projects
Project configuration and Mix of HAL
HAL only LL only Comments
drivers to be included and LL
Table 16. LL versus HAL code generation: STM32CubeMX generated header files
Generated Mix of HAL
HAL only LL only Comments
header files and LL
Table 18. LL versus HAL: STM32CubeMX generated functions and function calls
Generated source
HAL only LL only Mix of HAL and LL Comments
files
Table 18. LL versus HAL: STM32CubeMX generated functions and function calls (continued)
Generated source
HAL only LL only Mix of HAL and LL Comments
files
Figure 172. Project root folder with corresponding custom generated files
Define= USE_STM32F429I_DISCO
– Enabling HAL modules in generated stm32f4xx_hal_conf.h
HAL modules can be enabled using the following syntax after the [Others] line:
Syntax
HALModule = <ModuleName1>; <ModuleName1>;
Example
HALModule=I2S;I2C
[Groups]
Drivers/BSP/STM32F429IDISCO=C:\Users\frq09031\STM32Cube\Repository\STM3
2Cube_FW_F4_V1.14.0\Drivers\BSP\STM32F429I-
Discovery\stm32f429i_discovery.c;
C:\Users\frq09031\STM32Cube\Repository\STM32Cube_FW_F4_V1.14.0\Drivers\
BSP\STM32F429I-Discovery\stm32f429i_discovery.h
Lib=C:\Users\frq09031\STM32Cube\Repository\STM32Cube_FW_F4_V1.14.0\
Middlewares\Third_Party\FreeRTOS\Source\portable\IAR\ARM_CM4F\portasm.s
Doc=$PROJ_DIR$\..\readme.txt
[Others]
Define = USE_ STM32F429I_DISCO
HALModule = UART;SPI
Upon project generation, the presence of this .extSettings file triggers the update of:
• the project MyF429IDiscoProject.ewp file in EWARM folder (see Figure 175),
• the stm32f4xx_hal_conf.h file in the project Inc folder (see Figure 176)
• the project view within EWARM user interface as shown in Figure 177 and Figure 178.
Figure 177. New groups and new files added to groups in EWARM IDE
For working with Arm Cortex-M dual-core products, STM32CubeMX generates code for
both cores automatically according to the context assignment and initializer choices made in
the user interface (see Section 4.6: Pinout & Configuration view for STM32H7 dual-core
product lines for details).
Figure 180. Startup and linker files for STM32H7 dual-core devices
The Device tree in Linux is used to provide a way to describe non-discoverable hardware.
STMicroelectronics is widely using the device tree for all the platform configuration data,
including DDR configuration.
Linux developers can manually edit device tree source files (dts) but as an alternative
STM32CubeMX offers a partial device-trees generation service to reduce effort and to ease
new comers hands-on. STM32CubeMX intends to generate partially device trees
corresponding to board level configuration. Partial means that the entire (board level)
device-trees are not generated but only main sections that usually implies huge efforts and
can cause compilation errors and dysfunction:
• Folders structure and files to folders distribution
• dtsi and headers inclusions
• pinCtrl and clocks generation
• System-On-Chip device nodes positioning
• Multi-core related configurations (Etzpc binding, resources manager binding,
peripherals assignment)
For more details refer to “Device Tree for Dummies” from Thomas Petazzoni, available on
https://elinux.org.
For more information about STM32MP1 Series device tree specificities, refer to ST Wiki
https://wiki.st.com/stm32mpu.
The DT generation path can be configured from the Project Manager view, in the Advanced
Settings tab, under OpenSTLinux Settings (see Figure 184). For each Device tree
STM32CubeMX generates Device tree source (DTS) files.
The device tree nodes generated by STM32CubeMX can be completed by filling the user
sections, following the device tree bindings available in TF-A source code
docs/devicetree/bindings/ folder.
This section describes the configuration and C code generation process. It takes as an
example a simple LED toggling application running on the STM32F4DISCOVERY board.
STM32CubeMX views are then populated with the selected MCU database (Figure 192).
Optionally, remove the MCUs Selection bottom window by deselecting Window> Outputs
submenu (see Figure 193).
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 195).
c) You can also configure the RCC to use an external oscillator as potential clock
source (see Figure 196).
Answering No will require to provide a name and location for the report only.
As shown in Figure 199, a confirmation message is displayed when the operation is
successful.
2. Open the .pdf report using Adobe Reader or the .txt report using your favorite text
editor. The reports summarize all the settings and MCU configuration performed for the
project.
2. First select the clock source (HSE, HSI or PLLCLK) that will drive the system clock of
the microcontroller.
In the example taken for the tutorial, select HSI to use the internal 16 MHz clock (see
Figure 201).
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 202).
– Select the external PLL clock source and the HSI or HSE as the PLL input clock
source.
3. Keep the core and peripheral clocks to 16 MHz using HSI, no PLL and no prescaling.
Note: Optionally, further adjust the system and peripheral clocks using PLL, prescalers and
multipliers:
Other clock sources independent from the system clock can be configured as follows:
– USB OTG FS, Random Number Generator and SDIO clocks are driven by an
independent output of the PLL.
– I2S peripherals come with their own internal clock (PLLI2S), alternatively derived
by an independent external clock source.
– USB OTG HS and Ethernet Clocks are derived from an external source.
4. Optionally, configure the prescaler for the Microcontroller Clock Output (MCO) pins that
allow to output two clocks to the external circuit.
5. Click to save the project.
6. Go to the Configuration tab to proceed with the project configuration.
b) with a 16 MHz APB clock (Clock tree view), set the prescaler to 16000 and the
counter period to 1000 to make the LED blink every millisecond.
4. Select the Configuration view. FatFs and USB buttons are then displayed.
5. FatFs and USB using default settings are already marked as configured . Click
FatFs and USB buttons to display default configuration settings. You can also change
them by following the guidelines provided at the bottom of the window.
3. Select the Code Generator tab to choose various C code generation options:
– The library files copied to Projects folder.
– C code regeneration (e.g. what is kept or backed up during C code regeneration).
– HAL specific action (e.g. set all free pins as analog I/Os to reduce MCU power
consumption).
In the tutorial example, select the settings as displayed in Figure 219 and click OK.
Note: A dialog window appears when the firmware package is missing. Go to next section for
explanation on how to download the firmware package.
To solve this issue, execute the next two steps. Skip them otherwise.
3. Select Help > Updater settings menu and adjust the connection parameters to match
your network configuration.
4. Click Check connection. The check mark turns green once the connection is
established.
6. Finally, a confirmation message is displayed to indicate that the C code generation has
been successful.
7. Click Open Folder to display the generated project contents or click Open Project to
open the project directly in your IDE. Then proceed with Section 10.8.
2. As an example, select .eww file to load the project in the IAR™ EWARM IDE.
The htim3 structure handler, system clock, GPIO and TIM3 initialization functions are
defined. The initialization functions are called in the main.c. For now the user C code
sections are empty.
4. In the IAR™ IDE, right-click the project name and select Options.
5. Click the ST-LINK category and make sure SWD is selected to communicate with the
STM32F4DISCOVERY board. Click OK.
6. Select Project > Rebuild all. Check if the project building has succeeded.
This C code implements the weak callback function defined in the HAL timer driver
(stm32f4xx_hal_tim.h) to toggle the GPIO pin driving the green LED when the
timer counter period has elapsed.
8. Rebuild and program your board using . Make sure the SWD ST-LINK option is
checked as a Project options otherwise board programming will fail.
9. Launch the program using . The green LED on the STM32F4DISCOVERY board
will blink every second.
10. To change the MCU configuration, go back to STM32CubeMX user interface,
implement the changes and regenerate the C code. The project will be updated,
preserving the C code in the user sections if option in
Project Manager’s Code Generator tab is enabled.
The tutorial consists in creating and writing to a file on the STM32429I-EVAL1 SD card using
the FatFs file system middleware.
To generate a project and run tutorial 2, follow the sequence below:
1. Launch STM32CubeMX.
2. Select File > New Project. The Project window opens.
3. Click the Board Selector Tab to display the list of ST boards.
4. Select EvalBoard as type of Board and STM32F4 as Series to filter down the list.
5. Answer Yes to Initialize all peripherals with their default mode so that the code is
generated only for the peripherals used by the application.
6. Select the STM32429I-EVAL board and click OK. Answer No in the dialog box asking
to initialize all peripherals to their default modes (see Figure 237). The Pinout view is
loaded, matching the MCU pinout configuration on the evaluation board (see
Figure 238).
7. From the Peripheral tree on the left, expand the SDIO peripheral and select the SD 4
bits wide bus (see Figure 239).
8. Under the Middlewares category, check SD Card as FatFs mode (see Figure 240).
b) Configure the clock tree from the clock tab (see Figure 242).
10. In the Project tab, 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 244). 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. if not already done through CubeMX User
interface (under Linker Settings from Project Manager's project tab), adjust the heap
and stack sizes (see Figure 245).
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:
/* 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 247). 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 247.
– 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 248).
– Some peripherals for which consumption is unavailable or negligible are
highlighted with ‘*’ (see Figure 248).
The next figures show on the left the original step and on the right the step updated with
several optimization actions.
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 250).
See Figure 256 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 259).
3. Select the Asynchronous mode for the USART2 peripheral (see Figure 260).
4. Check that the signals are properly assigned on pins (see Figure 261):
– SYS_SWDIO on PA13
– TCK on PA14
– USART_TX on PA2
– USART_RX on PA3
13.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 262).
3. Click TIM2 and change the prescaler to 16000, the Word Length to 8 bits and the
Counter Period to 1000 (see Figure 264).
4. Enable TIM2 global interrupt from the NVIC Settings tab (see Figure 265).
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 269).
3. The Tera Term window displays a message coming from the board at a period of a few
seconds (see Figure 270).
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 272 and Figure 273).
If needed, modify the search criteria and the filter options and restart the search
process by clicking the Search button.
The color shading and the Comments column indicate the level of matching:
– Exact match: the MCU is fully compatible with the current project (see Figure 273
for an example).
– Partial match with hardware compatibility: the hardware compatibility can be
ensured but some pin names could not be preserved. Hover the mouse over the
desired MCU to display an explanatory tooltip (see Figure 272 for an example).
– Partial match without hardware compatibility: not all signals can be assigned to the
exact same pin location and a remapping will be required. Hover the mouse over
the desired MCU to display an explanatory tooltip (see Figure 273 for an
example).
Figure 273. 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 276. Additional software components enabled for the current project
The pack name highlighted in green indicates that all conditions for the selected
software components resolve to true. If at least one condition is not resolved, the pack
name is highlighted in orange.
7. Select the Project manager project tab to specify project parameters (see Figure 278),
and choose IAR™ EWARM as IDE.
This tutorial demonstrates how to achieve a functional project using the X-Cube-BLE1
software pack.
Below the prerequisites to run this tutorial:
• Hardware: NUCLEO-L053R8, X-NUCLEO-IDB05A1 and mini-USB cable (see
Figure 280)
• Tools: STM32CubeMX, IDE (Atollic® or any other toolchain supported by
STM32CubeMX)
• Embedded software package: STM32CubeL0 (version 1.10.0 or higher), X-Cube-BLE1
1.1.0 (see Figure 281).
• Mobile application (see Figure 282): STMicroelectronics BlueNRG application for iOS®
or Android™
c) Click OK to apply the selection to the project and close the window. The left panel
Additional Software section is updated accordingly.
5. Enable peripherals and GPIOs from the Pinout tab (see Figure 287):
a) Configure USART2 in Asynchronous mode.
b) Configure SPI1 in Full-duplex master mode.
c) Left-click the following pins and configure them for the required GPIO settings:
PA0: GPIO_EXTI0
PA1: GPIO_Output
PA8: GPIO_Output
d) Enable Debug Serial Wire under SYS peripheral.
Check that the icon turns to . Click OK to close the Configuration window.
9. Build and Run the SensorDemo application from the Atollic® TrueStudio®:
a) Configure the project properties (see Figure 294)
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 295).
Click GFXSIMULATOR from the configuration view to open the Graphics simulator user
interface (see Figure 303).
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 304.
2. Adjust the simulator parameter values from the left center panel, compare to current
configuration settings in the right panel (see Figure 305).
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.
1. From the Configuration view, click GRAPHICS to open the configuration window.
2. STM32CubeMX highlights in red when the selected LTDC pixel format is not
compatible with TouchGFX, as exemplified in Figure 308. Adjust LTDC settings to solve
the issue (Figure 309).
3. STM32CubeMX highlights in red (as exemplified in Figure 310) when the path to
TouchGFXDesigner.exe is missing.
Select the “ST-TouchGFXDesigner.exe not found” text in red to reveal the icon.
Click on it and browse to TouchGFX installation folder: select ST-TouchGFXDesigner exe
file from the designer folder (see Figure 311).
2. Then, click on the “Execute Button” to open ST-TouchGFXDesigner user interface (see
Figure 313).
20 FAQ
20.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 316).
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)
20.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.
20.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 318 for an example.
The clock source frequency can then be edited and the external source selected, see
Figure 319.
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 322 and Figure 323).
Figure 326. 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 327).
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 329).
Unchecking allows STM32CubeMX shifting blocks around
and freeing a block for the Ethernet MII mode. (see Figure 330).
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 331).
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 333).
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 337: 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 338: Enabling the TouchSensing
peripheral, Figure 339: Touch-sensing sensor selection panel and Figure 340:
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 341 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 by the tool end up in the STM32CubeMX project folder.
They are exclusive in a given project and configuration with FreeRTOS is not yet supported.
Application projects generated with STM32CubeMX can be found in the project folder of the
STM32CubeWB MCU package.
This package can be installed through STM32CubeMX following the standard procedure
described in Section 3.4.2: Installing STM32 MCU packages.
BLE configuration
To enable BLE some peripherals (RTC, HSEM, RF) must be activated first.
Then, an application type must be selected, it can be one among Transparent mode, Server
profile, Router profile or Client profile.
Finally, the mode and other parameters relevant to this application type must be configured.
Note: The BLE Transparent mode and all Thread applications require either the USART or the
LPUART peripheral to be configured as well.
Thread configuration
To enable Thread some peripherals (RTC, HSEM, RF) must be activated first.
Then, an application type must be selected and the relevant parameters configured.
STM32 microcontroller part numbers are codified following the below naming conventions:
• Device subfamilies
The higher the number, the more features available.
For example STM32L0 line includes STM32L051, L052, L053, L061, L062, L063
subfamilies where STM32L06x part numbers come with AES while STM32L05x do not.
The last digit indicates the level of features. In the above example:
– 1 = Access line
– 2 = with USB
– 3 = with USB and LCD.
• Pin counts
– F = 20 pins
– G = 28 pins
– K = 32 pins
– T = 36 pins
– S = 44 pins
– C = 48 pins
– R = 64 (or 66) pins)
– M = 80 pins
– O = 90 pins
– V = 100 pins
– Q = 132 pins (e. g. STM32L162QDH6)
– Z = 144 pins
– I = 176 (+25) pins
– B = 208 pins (e. g. STM32F429BIT6)
– N = 216 pins
• Flash memory sizes
– 4 = 16 Kbytes of Flash memory
– 6 = 32 Kbytes of Flash memory
– 8 = 64 Kbytes of Flash memory
– B = 128 Kbytes of Flash memory
– C = 256 Kbytes of Flash memory
– D = 384 Kbytes of Flash memory
– E = 512 Kbytes of Flash memory
– F = 768 Kbytes of Flash memory
– G = 1024 Kbytes of Flash memory
– I = 2048 Kbytes of Flash memory
• Packages
– B = SDIP
– H = BGA
– M = SO
– P = TSSOP
– T = LQFP
– U = VFQFPN
– Y = WLCSP
Figure 351 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 352). 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
21 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. For additional information about ST trademarks, please refer to www.st.com/trademarks. All other
product or service names are the property of their respective owners.
Information in this document supersedes and replaces information previously supplied in any prior versions of this document.