Revision as of 15:10, 6 September 2023 by Registered User (Remove a duplicate image.)

Tools installation and first testClock.png 45min

Target description
Teach how to install the main tools for programming the STM32:

  • STM32CubeMX, a tool to set and graphically program all STM32 boards and products
  • STM32CubeIDE, the free IDE to develop the STM32 software
  • STM32CubeProg, a tool to load/spy software in the STM32 memory
  • An MCU software package with embedded examples, based on the selected device, e.g. STM32CubeL4, STM32CubeWBA, etc.

Having completed this tutorial, you should be able to open the STM32 professional ecosystem.
You should also manage to bring applications from the ecosystem onto the NUCLEO board.
Finally, you will be able to run the blinking LED example in debug mode.

Prerequisites

  • Computer with Windows 7 (or higher)
  • Java installed
  • web access

Hardware

  • A Nucleo board or a Development kit, e.g.:
    • NUCLEO-L476RG[1] board (64-pin)
    • NUCLEO-WBA52CG[2] board (48-pin)
  • USB Type-A to Mini-B cable

1. Install an IDE

Clock.png 10min
Download and install your preferred IDE. Currently supported options are: STM32CubeIDE[3], Keil uVision[4], IAR EW[5], Microsoft VSCode[6] with the STM32 extension[7].
Follow the instructions on the product's webpage. In case you are using this IDE, you can skip the installation of STM32CubeMX in the following section. With other IDEs, it is necessary to additionally install STM32CubeMX.
Below are the instructions for installing STM32CubeIDE and VSCode.

1.1. Install CubeIDE

STM32CubeIDE is the Integrated Development Environment to develop STM32 software.

  • Download STM32CubeIDE.

Stepbystep Download STM32CubeIDE.png

  • Register on www.st.com web site if necessary.
  • Unzip the downloaded file and launch the STM32CubeIDE-xxx corresponding to your OS.

STM32CubeIDE is now installed on your computer, enjoy!

1.2. Install VSCode with the STM32 extension

  • Download VSCode.

File:STM32StepByStep:vsc install.png

  • Run the setup file.
  • For basic functionality, you also need to install:
    • STM32CubeMX (instructions in the following section)
    • CubeCLT[8] or CubeIDE
  • For added functionality, you can also install:
  • Make sure these tools (locations of their executables) are referenced in the System path variable.
  • Launch VSCode, go to "Extensions" tab.
  • Search for "STM32 VS Code Extension" and install it (other necessary extensions will be installed automatically).
  • Reload of VSCode is needed before continuing.
Info white.png Information
There is a Github repository [11] containing many useful tips, even though it was created before the official extension's release.

2. Install STM32CubeMX

Clock.png 10min
STM32CubeMX is the tool to graphically program the STM32.

  • Download STM32CubeMX[12].

Stepbystep Download STM32CubeMX.png

  • Register on www.st.com web site if necessary.
  • Unzip the downloaded file and launch the SetupSTM32CubeMX-xxx corresponding to your OS.
  • For use with VSCode, make sure that the System path variable contains reference to CubeMX executable.

STM32CubeMX is now installed on your computer.

3. Install STM32CubeProg

Clock.png 5min
STM32CubeProgrammer is a tool load/spy software in STM32.

  • Download STM32CubeProg[13].

Download STM32CubePROG.png

  • Unzip the downloaded file and launch the SetupSTM32CubeProgrammer-xxx.exe corresponding to your OS, and follow the instructions.

STM32 USB driver and STM32CubeProg are now installed on your computer.

4. Download firmware package for your device

Clock.png 10min

  • In case you are using STM32CubeIDE, use the built-in version of STM32CubeMX - open STM32CubeIDE.
  • Otherwise, open STM32CubeMX.
  • In both cases, click Manage embedded software packages in Help.
  • Check the last release version of the correct package, e.g. STM32CubeL4, STM32CubeWBA, etc.
  • Click Install (it may take a long time).

Stepbystep Download STM32CubeL4.png

  • Now the chosen libraries and examples are installed at the following location C:\Users\myname\STM32Cube\Repository\STM32Cube_FW_XX_Vx.xx.x (where XX is the MCU series, e.g. L4, WBA, etc.).

5. Launch the IDE and load my first program

Clock.png 10min
Launch your preferred IDE and follow the necessary steps to debug a program on the MCU.
Below are the steps for STM32CubeIDE and VSCode. Directory path to the example project applies to other IDEs as well.

5.1. Load example into CubeIDE

Use the debug configuration

  • Launch STM32CubeIDE.
  • If STM32CubeIDE asks, select the default workspace.
  • In File STM32CubeIDE menu, click on Open Projects from File System.

Stepbystep Import Project.png

  • In the window, click Directory and select C:\Users\myname\STM32Cube\Repository\STM32Cube_FW_XX_Vx.xx.x\Projects\YYYY\Examples_LL\GPIO\GPIO_InfiniteLedToggling (where XX is the MCU series, e.g. L4, WBA, etc. and YYYY is the board name).
Info white.png Information
The path may be different depending on the product
  • Select the project file inside folder
    • \STM32CubeIDE for more recent projects
    • \SW4STM32\YYYY (where YYYY is the board name) for older projects
  • In case of an older project, accept the popup, asking for conversion.

Project Converter.png

  • Click on Build icon to build the project.


Info white.png Information
Ensure that the CN2 jumper is on, so there would not be any hardware problem.
Ensure also that the ST-Link driver is well installed.

Now your project is under STM32CubeIDE

  • Default STM32CubeIDE settings are adequate for this tutorial.

5.2. Load example into VSCode

Info white.png Information
Currently, the STM32 extension is not able to load the example projects because of their file structure. The workaround is to create an empty project and copy the necessary files/code.
  • Click on Create a new application project.

File:STM32StepByStep:vsc create project.png

  • Click on Access to board selector, search for your board, then Start Project.
  • Choose No when asked Initialize all peripherals in their default mode?.
  • Under the Project Manager / Project tab, set the name and location for the project. Choose STM32CubeIDE for Toolchain / IDE.

STM32StepByStep:cubemx setup1.png

  • Under the Project Manager / Advanced Settings tab, set LL for all fields under Driver Selector.

STM32StepByStep:cubemx setup2.png

  • Click on Generate code. When the process finishes, click on Open Folder.
  • Switch to VSCode, select Import a local project and navigate to the created project folder.
  • Select the .cproject file and Open.
  • In the pop-up window, choose Debug.

STM32StepByStep:vsc import project2.png

  • In the built-in file explorer, open Core / Src / main.c.
  • Copy the following code into the while loop in the main() function:
LL_GPIO_TogglePin(LD1_GPIO_Port, LD1_Pin);
LL_mDelay(250);
Info white.png Information
The LED name might be different depending on the target board. Check the CubeMX project for the pin name.
  • Click on the Build icon.

File:STM32StepByStep:vsc run1.png

  • In the pop-up window, choose Debug.

6. Debug my first program

6.1. Debug with CubeIDE

  • Click on Debug icon to launch and debug the project.

Stepbystep Debug STM32CubeIDE.png

  • Please ensure to click on “Shared ST-Link” option on Debug configurations and Debugger tab.
  • Click Resume icon to continue the program execution.

Stepbystep Resume STM32CubeIDE.png

Info white.png Information
To power the NUCLEO-L476RG, use its CN1 connector to connect it with a computer through an USB Type-A to Mini-B cable.

6.2. Debug with VSCode

  • Under the Run and debug tab, click on the Start debugging icon.

File:STM32StepByStep:vsc run2.png

  • Place a breakpoint in main.c and press F5 to let the program run until this point.

Now you are able to:

  • find STM32 libraries
  • open a project (example)
  • load a project in STM32CubeIDE
  • execute a project in debug mode
  • make a LED blink

Now you have on your computer:

  • libraries for your selected MCU
  • examples for your selected MCU
  • STM32CubeProg (to communicate with the MCU)
  • STM32CubeMX (to graphically generate your project)
  • STM32CubeIDE (to code)

7. References



Arrow right.png Next step