How to get started with STM32CubeMX2

LED toggle example

Project creation

Device selection

Go to the Home and click on Board to initiate a board-based project. From the Home view, click on Board to initiate a board-based project

../../_images/HowToQuicklyStart-Fig1.webp

Create a project from a board

  • Select the board (1): For this example , we use NUCLEO-C562RE.

  • Click Continue to provide the project details (2).

  • Enter the project name (3): example Toggle_LED.

  • Specify the project location (4): example C:\Projects.

  • Click Automatically Download, Install & Create Project (5).

../../_images/HowToQuicklyStart-Fig2.webp

Project setup

After creating the project, open Project settings to display and manage the project. This tab contains the following:

  • Project settings (1): Displays the project settings, including the project name, location, selected device and the software project.

  • IDE project generation settings (2): Manages the IDE project. See the IDE project generation for more details.

  • Left bar (3): contains quick access icons for frequently used features. See Menu bar and left bar for further details.

  • Packs management (4): Manages the installed packs.

  • Global services settings (5): Manages the global services settings.
    • HAL System init settings (6): Manages Code Generation parameters for common System files.

    • HAL Common definitions (7): Manages Code Generation parameters for Core Files.

For this tutorial, only the pinout configuration is required.

../../_images/HowToQuicklyStart-Fig3.webp

Project & IDE project settings

../../_images/HowToQuicklyStart-Fig4.webp

Packs management & Global services settings

../../_images/HowToQuicklyStart-Fig5.webp

HAL system init settings

../../_images/HowToQuicklyStart-Fig51.webp

HAL common definitions

Pinout assignment

  • Open the pinout view (1): Click on its icon from the left bar.

  • Locate PA5 (2): Use the search function to find its location. PA5 is the GPIO that is connected to the LED we want to use on this NUCLEO board.

Note

The Reset Pinout action clears reserved and GPIO signals while preserving peripheral-configured signals and user labels.

../../_images/HowToQuicklyStart-Fig6.webp

Pinout view

  • Assign PA5 to GPIO (3): Right-click the pin and select Assign signal > GPIO.

../../_images/HowToQuicklyStart-Fig7.webp

Pinout configuration

Note

The table view can also be used to configure pins. See Pinout for further details.

GPIO configuration

To configure GPIO component:

  • Open the configuration (1): Right-click on the pin and select Go to configuration GPIO.

../../_images/HowToQuicklyStart-Fig8.webp

Access to GPIO configuration

  • Locate the pins PA5 (2): Extend the Pins section to find the pins.

../../_images/HowToQuicklyStart-Fig9.webp

GPIO configuration

  • Set PA5 mode to output (3): Extend the configuration then change the mode to output.

../../_images/HowToQuicklyStart-Fig10.webp

PA5 pin configuration

IDE project generation

Project generation

After configuring PA5 pins, follow these steps to generate the IDE project:

  • Select format (1): Choose the desired format. Available formats include IAR Embedded Workbench for ARM, CMake and Open-CMSIS. The default is CMake.

  • Select toolchain (2): A default toolchain is automatically created. However, the Open CMSIS format currently supports multiple toolchains. In this case, the user can explicitly choose GCC or IAR instead of the default AC6.

  • Select destination (3): Browse and select the folder for the IDE project. The default path is at the root folder of the created STM32CubeMX2 project.

  • Generate IDE project (4): Click the Generate button to create the IDE project.

../../_images/HowToQuicklyStart-Fig11.webp

Project settings

Note

  • The Show on disk option allows you to view the generated files on your disk when the IDE project generation is completed.

../../_images/HowToQuicklyStart-Fig12.webp

Project opening

Navigate to the project’s location:

  • Project location (1): The project is located at C:\Projects.

  • Project configuration file (2): This .ioc2 file is the main configuration file for the STM32CubeMX2 project.

  • IDE project folder (3): Contains the IDE-specific files and folders.

../../_images/HowToQuicklyStart-Fig13.webp

Project directory

Open Toggle_LED project with STM32CubeIDE for VSCode , and edit the main.c file.

  • Write the application code (1): In the main function, add the highlighted code to toggle GPIO pins with delays.

  • Build the code (2): Click the Build button to compile the code.

  • Run the code (3): Click the Launch button to execute the code on the target hardware.

../../_images/HowToQuicklyStart-Fig14.webp

main.c file

I²C example

Project creation

create a project by following the steps described in Create a project from a board and Project setup.

For this demonstration, pinout and clock configurations remain as default.

I²C activation

  • Open the peripheral view (1): Click its icon from the left bar.

  • Extend connectivity section (2).

  • Enable I²C1 (3): Locate I²C1 and change its status from Disabled to I²C by selecting the option from the dropdown menu.

Note

Refer to Peripherals for more details on how to activate peripherals.

Note

The system displays a notification indicating that the peripheral I2C1 signals are assigned to specific pins.

../../_images/HowToQuicklyStart-Fig17.webp

I²C configuration

Once enabled, the user can open the software configuration following these steps:

  • Open the I²C1 Settings (1).

  • Update the resources allocation (2): Change the default assignment if needed.

  • Update the configuration (3): Expend the different sections to list all available parameters.

../../_images/HowToQuicklyStart-Fig18.webp

Access I²C configuration

  • Enable event interruption and error detection (4): Extend the system section to get the list of interruptions.

../../_images/HowToQuicklyStart-Fig19.webp

Enable I²C2 event and error interrupts

  • The priority level can be modified either from the I²C configuration or from the NVIC view.

Note

The NVIC view can be accessed from the Peripheral View under the System category.

../../_images/HowToQuicklyStart-Fig20.webp

I²C2 interrupts in NVIC view

IDE project generation

Apply the same steps described in the IDE project generation section from LED toggle example.

Additional articles

How to create a new project with STM32CubeMX2