Using STM32Cube native project structure and hardware abstraction layer ¶
This first case considers the use of the full suite of STM32Cube tools, including the STM32CubeMX configuration tool and the free integrated development environment (IDE) from ST. The STM32Cube hardware abstraction layer, with HAL or LL API, is used as well.
Create a project with STM32CubeMX ¶
If not already done, download and install the MCU configuration tool. Depending on the STM32 device, install either STM32CubeMX or STM32CubeMX2.
To start a new project, open STM32CubeMX. Select the microcontroller unit (MCU) and configure it, including pins, clock, and required peripherals. Then generate a project for STM32CubeIDE. The generated project contains the necessary software drivers and source code for MCU initialization. Add any optional middleware with its initialization code.
Note
For more details, refer to the STM32CubeMX user manual for STM32CubeMX or the STM32CubeMX2 documentation for STM32CubeMX2.
Open a project in STM32CubeIDE ¶
There are two free IDE options available from ST:
STM32CubeIDE, based on the Eclipse® CDT™ framework
STM32CubeIDE for Visual Studio Code, available as an extension pack for Microsoft® Visual Studio Code®
If not already done, download and install the chosen integrated development environment (IDE) from ST.
Note
Refer to the STM32CubeIDE user guide or the STM32CubeIDE for Visual Studio Code user guide.
Integrate other software components and custom code ¶
Add additional STM32Cube components available from ST, as well as proprietary source code or libraries, to the project.
For application code related to STM32Cube hardware abstraction layer (HAL), low-layer (LL), or middleware, refer to the basic examples available in the STM32 Example Library. Open these examples in the STM32CubeMX tool to review the related microcontroller unit (MCU) peripheral or middleware configuration.
Additional software components for the STM32Cube expansions are available on the ST GitHub repository or on www.st.com. For an overview of available software components for STM32 microcontrollers, refer to the STM32 MCU embedded software offer on the STM32 MCU Developer Zone.
Note
To add code to files generated by STM32CubeMX, place the code between specific user code sections. Otherwise, STM32CubeMX overwrites the code, when re-generating the project. In STM32CubeMX2, the mechanism is different: the generated code is kept in separate files.
Return to STM32CubeMX to add additional components and generate further initialization code ¶
To include and configure new STM32 peripherals in a project, enable and configure the peripherals in STM32CubeMX. Then generate the initialization code. Next, compile the project again with STM32CubeIDE.
STM32CubeMX can also add some STM32Cube middleware and generate the related initialization code.
It is possible at this stage to switch between STM32CubeMX and STM32CubeIDE.
Note
The same flow applies when using IAR Embedded Workbench® or Arm® Keil® Studio, MDK µVision as the integrated development environment (IDE) instead of STM32CubeIDE. In this case, adjust the option in the STM32CubeMX project manager to generate the correct project format for the IDE.
How to follow ST updates ¶
STM32CubeMX provides direct access to new updates of embedded software components, which are also published on www.st.com. ST GitHub is another way to follow regular updates of STM32Cube software components.