How to evaluate STM32 microcontrollers and prototype

Obtain a board

The STM32Cube ecosystem enables users to quickly evaluate a specific STM32 microcontroller and then start prototyping.

The recommended approach is to first select a Nucleo board or a Discovery kit according to the application requirements. There are two quick ways to select the appropriate Nucleo board:

  1. select the microcontroller, then search for the most suitable Nucleo board that includes the closest microcontroller.

  2. if the STM32 microcontroller is already known, go directly to the Nucleo board selector and use the Part Number filter.

For example, by typing H5 in the search bar, the selector displays the Nucleo boards that include a microcontroller from the STM32H5 series.

../../_images/Nucleo_select.png

The Nucleo board or Discovery kit are available from several distributors. The availability and price are shown on the Nucleo product page under the Sample & Buy tab. For example, see the NUCLEO-H563ZI board.

Depending on the selected board, a USB mini type B cable, a USB micro type B cable, or a USB Type-C® cable might be required to connect the board to a PC.

Two possible step-by-step procedures are described below to quickly set up the environment and run a blinking LED on a board. Use the Start in the STM32CubeMX tool procedure if the board is listed in this table. Otherwise, use the Start in STM32 Example Library procedure.

Download and install STM32CubeMX tool

STM32CubeMX is a user-friendly configuration and code generation tool for STM32 MCUs. It is available for Windows, macOS, and Linux. It allows the quick generation of a C code project for a board.

Download and install STM32CubeMX on the host PC.

Open STM32CubeMX on the host computer, create a new project from board, and select your Nucleo board.

In the STM32CubeMX options pop-up window, ensure all software components are selected, and tick Generate demonstration code.

STM32CubeMX allows:

  • The graphical configuration of the MCU pins

  • The enabling of peripherals

  • Managing many more software components in your project

Before carrying out any more configuration, move on to the following step the development flow

Enter the settings of the project in the Project Manager tab like a name for the project and a project location directory on the host computer; select STM32CubeIDE in the Toolchain / IDE field.

Click Generate code.

After the project is generated, open the generated project folder from the pop-up window.

Download and install STM32CubeIDE tool

download and install the free integrated development environment (IDE) from ST.

After installing STM32CubeIDE, open the project by selecting:

File > Open Projects from File System

Then select the folder generated by STM32CubeMX.

Note

If the preferred interface is STM32CubeIDE for Visual Studio Code, generate the CMake format from STM32CubeMX. Then open the project in STM32CubeIDE for Visual Studio Code by selecting:

  • File > Open Folder

Then launch CMake by clicking on the CMake icon in the vertical toolbar and build the project.

Flash and debug

Connect the ST-LINK debugger embedded on the Nucleo board to the PC through USB. Launch a run command from the IDE to flash the binary onto the Nucleo target and start running the software.

Note

A pop-up window may prompt for the update of the firmware version of the in-circuit ST-LINK debugger/programmer embedded on the Nucleo board. Click Upgrade, keeping the default settings. After the process is completed, close the window and launch the run command again.

The software is now running. Press the user button several times to observe the LEDs flashing on and off.

At this stage, the development environment is ready.

Further steps

Enable additional peripherals and configure new GPIOs in the STM32CubeMX tool, then regenerate the code. In this case, recompile the project with STM32CubeIDE. Some middleware, such as USB, file system, or an RTOS such as FreeRTOS™ or ThreadX, can also be configured and added.

Add custom C code to the project by calling STM32Cube hardware abstraction layer (HAL) or low-layer (LL) application programming interfaces (APIs) to access STM32 resources and peripherals. The STM32Cube HAL is an STM32 embedded software layer that maximizes portability across the STM32 portfolio. The LL APIs provide a fast, lightweight, expert-oriented layer that is closer to the hardware than the HAL. If needed, HAL and LL APIs can be used simultaneously, with some restrictions.

Refer to the STM32 Example Library, which contains many basic examples. These well-tested code examples demonstrate how to use the hardware abstraction layer (HAL) or low-layer (LL) application programming interfaces (APIs). Copy and paste code into your project as needed.