Tools installation and first test 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.:
- USB Type-A to Mini-B cable
1. Install an IDE
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.
- 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
- STM32CubeMX (instructions in the following section)
- 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.
2. Install STM32CubeMX
10min
STM32CubeMX is the tool to graphically program the STM32.
- Download STM32CubeMX[12].
- 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
5min
STM32CubeProgrammer is a tool load/spy software in STM32.
- Download STM32CubeProg[13].
- 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
- 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).
- 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
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.
- 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).
- Select the project file inside folder
- \STM32CubeIDE for more recent projects
- \SW4STM32\YYYY (where YYYY is the board name) for older projects
- \STM32CubeIDE for more recent projects
- In case of an older project, accept the popup, asking for conversion.
- Click on Build icon to build the project.
Now your project is under STM32CubeIDE
- Default STM32CubeIDE settings are adequate for this tutorial.
5.2. Load example into VSCode
- 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.
File:STM32StepByStep:vsc create project.png
- 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.
- Under the Project Manager / Advanced Settings tab, set LL for all fields under Driver Selector.
- 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.
- 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);
- 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.
- Please ensure to click on “Shared ST-Link” option on Debug configurations and Debugger tab.
- Click Resume icon to continue the program execution.
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