Frequently Asked Questions ¶
1. Is the selected STM32 series supported by HAL2 and the new generation of examples? ¶
The newest STM32 series, beginning with STM32C5, are supported by HAL2 and the new generation of examples. Refer to the Getting started with STM32Cube ecosystem documentation for more details about the overall ecosystem offering and the supported series. Refer to STM32 MCU Developer Zone for more details about the overall embedded software offering and the supported series.
2. Can I use these examples with STM32CubeMX ? ¶
No, the HAL2-based examples are not compatible with STM32CubeMX. They are designed to be used with STM32CubeMX2, the new generation of STM32CubeMX.
3. Can I replace HAL2 with HAL1 in these examples? ¶
No, the HAL2-based examples are not compatible with HAL1. They leverage the latest features of HAL2 and require its specific APIs and architecture.
4. Can I migrate existing HAL1-based examples to HAL2 ? ¶
Yes, you can migrate any existing HAL1-based projects to HAL2, but it requires a manual process of adapting the code to the new APIs and architecture of HAL2. You can refer to HAL1 to HAL2 migration guide for more details on the differences between HAL1 and HAL2, and the migration process.
5. How to find the project for my IDE in STM32 Example Library ? ¶
In the Select IDE column of STM32 Example Library, you can select the project for your IDE by looking for the corresponding value:
For STM32CubeIDE for Visual Studio Code, choose
cmake.For IAR Embedded Workbench® for Arm®, choose
EWARM.For Keil® MDK for Arm®, choose
open-cmis.
To understand the IDE support in HAL2-based examples, refer to What is an example?.
6. Can I download several examples in one go from STM32 Example Library ? ¶
No, you cannot download several examples in one go from STM32 Example Library. You need to download each example separately, and you will get several times the same dependencies (HAL, DFP, …).
For such needs, we recommend using STM32 Package Creator, which allows you to define your own custom package with the features you want, and download it in one go. This will provide you with a single package containing all the examples you need, along with the necessary dependencies, without duplication.
See How to get STM32Cube Software Examples? for more information about the delivery channels and the contents obtained with each of them.
7. How to obtain the STM32CubeMX2 configuration files for the examples? ¶
Almost all examples are provided with STM32CubeMX2 configuration files (
.ioc2) by default.
You can check in the
Configurable
column of
STM32 Example Library
if the example you are interested in is provided with a STM32CubeMX2 configuration file.
If the example is provided with a STM32CubeMX2 configuration file, you can download it from STM32 Example Library together with the example project (no specific selection required).
The STM32CubeMX2 configuration files are also provided (when available) in the STM32Cube MCU Package.
8. Where are the STM32CubeMX user sections in the HAL2-based examples? ¶
The HAL2-based examples are designed with a clear separation between the user code and the generated code. Therefore, the concept of STM32CubeMX user section is not required in HAL2-based examples.
The benefits of this new architecture are explained in Example architecture and How to port the example to another board.
If you want to add your own changes in the code generated by STM32CubeMX2, you can leverage the conflict resolution mechanisms of STM32CubeMX2. Read more about this in the STM32CubeMX2 user manual.
9. Why am I facing compilation issues with some examples and IAR Embedded Workbench® for Arm®? ¶
Few projects might be difficult to compile with IAR Embedded Workbench® for Arm® when working with a STM32Cube MCU Package.
On a Windows machine, the 260-character path length limit can break some IAR Embedded Workbench® for Arm® builds.
In this case IAR Embedded Workbench® for Arm® might report a build error like:
Filename
longer
than
260
characters.
The simpler solution is to download the project from STM32 Example Library, as the project obtained from STM32 Example Library will not have the long path issue. Otherwise, refer to the Getting started documentation of the selected STM32Cube MCU Package for precise instructions on how to circumvent this problem.
10. How to map the structure of the HAL1-based examples to the structure of the HAL2-based examples? ¶
In HAL1 examples, most logic is grouped in
Src/main.c, with generated user sections, plus dedicated files such as
stm32tnxx_hal_msp.c
and
stm32tnxx_it.c.
In HAL2 examples, this logic is split into layers with clear ownership:
application/main.ckeeps the infrastructure flow and callsmx_system_init().application/example.ccontains the use-case code (app_init(),app_process(),app_deinit()).[board_name]/generated/hal/mx_*.ccontains STM32 and peripheral resource configuration generated by STM32CubeMX2.
Read more about the architecture of HAL2-based examples in Example architecture.
The table below summarizes the main equivalences.
|
Major topic |
HAL1-based examples (STM32CubeMX) |
HAL2-based examples (STM32CubeMX2) |
|---|---|---|
|
Where is the user code from
|
In
|
The scenario code moves to
|
|
Where is the system clock configuration? |
In
|
In generated RCC services under
|
|
Where is HAL initialized? |
|
|
|
Where is the equivalent of
|
In
|
In
|
|
Where is the equivalent of
|
In
|
There is no separate MSP callback file by default.
Low-level resource setup and release (GPIO, DMA, IRQ, kernel clocks) are implemented directly in
|
|
Where are the ITs? |
Usually in
|
Peripheral IRQ handlers are generated with their resource unit, for example in
|
In short, the functional scenario is moved into
application/example.c.
Each HAL1 initialization block is moved to the related
mx_
generated service and its alias in
mx_hal_def.h.
HAL2-based examples are designed to avoid the need for user modifications in generated code, and to maximize the stability of user code.
HAL2-based examples are also thoroughly documented in their
README.md
files.
These
README.md
files contain important information about the scenario and how to use the example.
See
How to read an example
to discover how to read an example and get the most out of it.