2026-03-16 7:30 AM - edited 2026-03-16 2:38 PM
This guide describes how to create a new project using STM32CubeMX2. It explains the main features and functions of the application. The guide covers essential steps such as microcontroller unit (MCU) selection, pin configuration, clock setup, peripheral and middleware management, and project generation. This guide helps users navigate the development environment efficiently.
STM32CubeMX2 is a graphical tool designed to simplify the configuration and initialization of STM32 microcontrollers. The tool provides an interface for selecting MCUs, configuring pins, clocks, peripherals, and middleware. It accelerates the development process and reduces the complexity of embedded system design. This article describes the step-by-step process for creating a new project in STM32CubeMX2, highlighting its main features and demonstrating how to generate ready-to-use code for a preferred development environment.
Install the following tools:
The hardware used in this tutorial is the NUCLEO-C562RE board.
After opening STM32CubeMX2, the main page displays key buttons to help you start developing code. On the right side, several resources are available to assist you during development:
In the lower-left corner of the STM32CubeMX2 main page, two icons help manage the development environment:
At the center of the page, three main options are available to begin a project:
After selecting to create a project via MCU, a screen appears that allows you to choose an STM32 microcontroller from a searchable list to begin project setup.
Type the MCU name, select the matching entry from the list, and click [Continue] to proceed.
Enter a name for the project (for example, NewProject) and update the project location to the desired folder. The project file path is autogenerated based on these inputs. Once set, click the [Automatically Download, Install & Create Project] button to proceed.
With the project created, explore the following features in STM32CubeMX2:
STM32CubeMX2 uses an updated color scheme compared to the previous version. The pin states are represented with new colors, as shown below:
Continued illustration in the image below.
Click the Clock tab to open the clock configuration interface. Customize the system and peripheral clocks according to project requirements. The graphical view presents a clock tree where you can adjust clock sources, prescalers, and multipliers.
STM32CubeMX2 introduces a new shortcut scheme. For example, you can navigate the clock tree by clicking and holding the mouse wheel to drag. To zoom in or out, hold the Ctrl key while scrolling.
By clicking in a given clock box, it is now possible to highlight all paths from that clock, making it easier to see the relationship between resources and clock sources.
Click the [Peripherals] button to open a side tab for configuring the peripherals used in the project. This tab provides a searchable and categorized list of all available peripherals,
It's organized into groups such as Analog, Security, Computing, System, Cortex, Connectivity, I/O, Memory, and Timers.
Select a category to display a list of available items. Click a specific item to open an interface for configuring its settings.
The "Quick menu" facilitates the navigation to locate the main points, such as selecting the GPIO(s) used by the select peripheral, the DMA, and interrupt.
STM32CubeMX2 also introduces the concept of "Code Preview", allowing the developer to check and copy the code based on those given settings. It is also possible to compare the code preview with a previous generated code, quickly spotting the effect of changes without having to re-generate the entire project.
Click the [Middleware & Utilities] button to open a side tab for managing middleware and utility components. Click [Add middleware] to include middleware packages such as FreeRTOS™. Similarly, add utility components to create a customized set of tools and services. Selecting Add middleware opens the configuration interface.
After activating one, such as FreeRTOS™, a new configuration tab becomes available, allowing you to select and activate the desired operating mode. Warning and
Click the [Parts] button to open a side tab to manage additional hardware parts. Click Add part(s) to include standalone parts to enhance the design.
Selecting [Add part] opens the configuration interface.
After integrating, a new configuration tab becomes available, allowing you to select and activate the desired operating mode.
After configuring all the pins, click the Project Settings button at the upper right. Scroll to the IDE project generation section to select your IDE or toolchain preferences, including IAR, CMake or Keil® with Open-CMSIS. CMake is the format used by the STM32Cube Visual Studio Code extension.
Click the [Generate] button to create the project files. Alternatively, click the yellow button on the lower left to generate the code directly.
Using the [Advanced] button allows the developer to adjust how the code is generated and regenerated.
The Global services allow HAL changes, such as changing the HAL time base and the addition of custom callbacks for IRQs.
The custom callback can be added per peripheral. For example, with UART, locate it quickly via the quick menu and enable the [Use register callback].
This article provides a walkthrough for configuring and generating STM32 projects using STM32CubeMX2, focusing on the STM32C5 series. It guides users through essential steps such as MCU selection, pin configuration, clock setup, peripheral and middleware management, and project generation with the preferred IDE.
By following this approach, developers can efficiently set up the hardware and software environment, enabling streamlined development and integration of complex features. This foundation allows users to build scalable and optimized applications tailored to specific project requirements.
Thanks for the explanation.
I've been experimenting with STM32CubeMX2. I also wanted to try creating a TrustZone project. In CubeMX, when creating the project, I could choose whether to create a project with or without TrustZone. Is this also possible with STM32CubeMX2? I haven’t found any settings for this. Is there a description for this use case?
Regards
Hi @fe3 ,
I'm glad to hear that you are experimenting with the new tool! While STM32C5 is a Cortex M33, it doesn't have TrustZone, that's why you don't see an equivalent option/setting as you normally do for other M33 series, such as STM32U5 and STM32H5.
Best Regards
Is there LL 2?
Hi @Witek_Lodz
Yes, there is a LL, the HAL2 and LL drivers architecture is similar to the HAL1-based one, the main difference is on the architecture level, where HAL2 uses LL as its foundation> HAL and LL layered drivers - STM32C5xx HAL Drivers 2.0.0 documentation. Same as it was on HAL1/LL1, LL drivers are register-based, they provide direct access to peripheral registers through inline functions that operate on the peripheral’s base address. The application is responsible for managing the peripheral’s state and ensuring correct usage of LL APIs, as they do not maintain any internal state or context. You can find a bit more here> STM32C5xx HAL Drivers 2.0.0 documentation
Hope this helps
In a project generated in STM32CubeMX2 and imported into VS Code, I do not have the Release compilation option. There is only debug.
Hi @TDrzy this is the expected behavior, STM32CubeMX2 has removed the release variant as part of the default creation. Only debug is automatically created. You can create the release or any variants, but I understand this can be a bit time consuming, so I'm working on expanding the knowledge base documentation with an article that guides the users on how to create build variants and release as well.
But this makes absolutely no sense. Where did this idea come from? This solution is impractical and only wastes my agent Ai's tokens.
Hi @TDrzy , point taken. I'll suggest bringing back the release build as part of the default generation. I appreciate your feedback