Using a custom project structure and leveraging STM32Cube tools and hardware abstraction layer

This case assumes that the user starts a project in the development environment. The user can use STM32CubeIDE, a third-party integrated developement environment such as IAR Embedded Workbench® for Arm®, Arm® Keil® Studio or MDK µVision, or another command-line interface-based development environment. Then, use ST tools to configure the microcontroller and set up an STM32Cube project as a reference.

Create a project in an IDE or a command-line interface-based environment

Use STM32CubeIDE, STM32CubeIDE for Visual Studio Code, or any other toolchain such as IAR Embedded Workbench®, Arm® Keil® Studio or MDK µVision, or another supported IDE. Refer to the project templates provided in the STM32Cube MCU packages, in the examples subfolder. These templates contain startup files, the interrupt vector table, and microcontroller initialization code.

Create a reference project with STM32CubeMX

If not already done, download and install the microcontroller configuration tool. Depending on the STM32 device, the web page prompts to install either STM32CubeMX or STM32CubeMX2.

The first step is to start a new project using the STM32CubeMX tool. Select the microcontroller unit (MCU) and configure it, including pins, clock, required peripherals and middleware. Then generate the project for the preferred integrated development environment (IDE), or as a Makefile or CMake project. The generated project contains the required software drivers and source code for MCU initialization.

Use this project as a reference to copy and paste code into the IDE project. At any time, new STM32 peripherals might need to be included and configured. Enable the required peripherals in STM32CubeMX, configure them, and regenerate the IDE project to update the initialization code in the C source files.

STM32CubeMX can also be used to add STM32Cube middleware and generate the related initialization code.

Compile the project generated by STM32CubeMX in the integrated development environment (IDE) to run or debug it as needed. Refer to the hundreds of available basic examples in the STM32 Example Library; some examples can also be opened in STM32CubeMX to check the related peripheral or middleware configuration.

Note

For more information, refer to the STM32CubeMX user manual for STM32CubeMX or the STM32CubeMX2 documentation for STM32CubeMX2.

Integrate additional software components and custom code

To fully own a project and add STM32Cube components, extract them from STM32Cube MCU packages or clone repositories from the ST GitHub account. Add custom proprietary source code and/or libraries to the project as well.

For application code related to STM32Cube HAL or LL, or middleware, refer to the hundreds of available basic examples in the STM32 Example Library.

Get additional software components from STM32Cube Expansions available on the ST GitHub repository or on www.st.com. Refer to the STM32 MCU embedded software offer on the STM32 MCU Developer Zone for an overview of available software bricks for STM32 MCUs.

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.