cancel
Showing results for 
Search instead for 
Did you mean: 

How to create a new project with STM32CubeMX2

B.Montanari
ST Employee

Summary

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.

Introduction

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.

Prerequisites

Install the following tools:

The hardware used in this tutorial is the NUCLEO-C562RE board.

1. Home page

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:

BMontanari_0-1771251511695.png

  1. STM32 MCU portfolio: Web page that helps you select the best STM32 microcontroller for your application.
  2. STM32 example browser: Collection of example projects to accelerate development.
  3. STM32 SDK builder: Tool for customizing and generating software development kits.
  4. STM32 documentation library: Technical documentation and reference materials.
  5. STM32 MCU community: Platform for community support and collaboration.
  6. STM32 MCU wiki: Knowledge base containing tutorials, frequently asked questions, and user guides.

In the lower-left corner of the STM32CubeMX2 main page, two icons help manage the development environment:

BMontanari_1-1771251511699.png

  1. Manages software packs, including downloading and updating device support packages and middleware components.
  2. Configures preferences and options for STM32CubeMX2.

At the center of the page, three main options are available to begin a project:

BMontanari_2-1771251511705.png

  1. MCU: Create a new project based on a microcontroller.
  2. Board: Create a new project based on a development board.
  3. Project: Open an existing project from the file system.

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.

2. Create application project from MCU

Type the MCU name, select the matching entry from the list, and click [Continue] to proceed.

BMontanari_3-1771251511708.png

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.

BMontanari_4-1771251511710.png

With the project created, explore the following features in STM32CubeMX2:

BMontanari_5-1771251511719.png

  1. Pinout: Configure the microcontroller pins and their functions visually.
  2. Clock: Configure the system and peripheral clocks.
  3. Peripherals: Enable and configure the hardware peripherals of the MCU.
  4. Middleware and utilities: Add and configure middleware components and utility libraries.
  5. Parts: View information about the MCU parts and package details.
  6. Project Settings: Configure the IDE, code generation, and HAL aspects, such as custom callbacks.
  7. IDE project generation: Manage settings related to generating the project for the chosen integrated development environment (IDE).

2.1 Pinout configuration tab

STM32CubeMX2 uses an updated color scheme compared to the previous version. The pin states are represented with new colors, as shown below:

BMontanari_6-1771251511720.png

Continued illustration in the image below.

BMontanari_7-1771251511735.png

2.2 Clock configuration tab

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.

BMontanari_8-1771251511743.png

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.

BMontanari_9-1771251511754.png

2.3 Peripheral tab

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.

BMontanari_10-1771251511756.png

Select a category to display a list of available items. Click a specific item to open an interface for configuring its settings.

BMontanari_11-1771251511762.png

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.

BMontanari_12-1771251511762.png

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.

BMontanari_13-1771251511769.png

2.4 Middleware & Utilities tab

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.

BMontanari_14-1771251511776.png

After activating one, such as FreeRTOS™, a new configuration tab becomes available, allowing you to select and activate the desired operating mode. Warning and

BMontanari_15-1771251511781.png

2.5 Parts tab

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.

BMontanari_16-1771251511786.png

Selecting [Add part] opens the configuration interface.

BMontanari_17-1771251511790.png

After integrating, a new configuration tab becomes available, allowing you to select and activate the desired operating mode.

BMontanari_18-1771251511793.png

BMontanari_19-1771251511796.png

2.6 Project settings and code generation

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.

BMontanari_20-1771251511799.png

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.

BMontanari_21-1771251511805.png

The Global services allow HAL changes, such as changing the HAL time base and the addition of custom callbacks for IRQs.

BMontanari_22-1771251511809.png

BMontanari_23-1771251511813.png

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].

BMontanari_24-1771251511817.png

3. Conclusion

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.

Related links 

Comments
fe3
Associate III

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

B.Montanari
ST Employee

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

Witek_Lodz
Associate

Is there LL 2? 

B.Montanari
ST Employee

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

TDrzy
Associate II

In a project generated in STM32CubeMX2 and imported into VS Code, I do not have the Release compilation option. There is only debug.

TDrzy_0-1776797546159.png

 

B.Montanari
ST Employee

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.

TDrzy
Associate II

But this makes absolutely no sense. Where did this idea come from? This solution is impractical and only wastes my agent Ai's tokens.

B.Montanari
ST Employee

Hi @TDrzy , point taken. I'll suggest bringing back the release build as part of the default generation. I appreciate your feedback

Version history
Last update:
‎2026-03-16 2:38 PM
Updated by: