How to program and debug the STM32 using the Arduino IDE
- Subscribe to RSS Feed
- Mark as New
- Mark as Read
- Bookmark
- Subscribe
- Email to a Friend
- Printer Friendly Page
- Report Inappropriate Content
on
ā2023-11-20
03:31 AM
- edited on
ā2023-12-07
05:26 AM
by
Laurids_PETERSE
Summary
This article covers how to program and debug your STM32 device with the Arduino IDE.
In this knowledge article, we explore the following main points:
- How to install the STM32 MCUs in the Arduino IDE
- How to program a simple blink LED based on the default example offered
- A brief description on how to start a debug session
1. Introduction
STM32 microcontrollers provide a full set of possibilities. This includes several mechanisms to program the MCU, through different hardware paths (SWD, USART, DFU etc.) and also different IDEs.
This allows the developer to use either our native programming tools, such as STM32CubeIDE or STM32CubeProgrammer. It can also be different IDEs, such as Arduinoās IDE.
Through the Arduino IDE, it is possible to enable the software to recognize our STM32 Nucleo, Discovery and Evaluation boards, including our 3D printer boards and wireless boards!
2. Hardware and software requirements
Hardware:
- NUCLEO-G071RE.
- 1 USB Cable Type micro-B (to NUCLEO-G071RE).
Software:
- Arduino IDE ā Software | Arduino
- Optional: STM32CubeProgrammer - STM32CubeProgrammer | STMicroelectronics
3. Development
3.1 Installing the STM32 support
To make your STM32 device compatible with Arduinoās IDE, we need to install the STM32 support. This can be achieved by clicking: Arduino IDE > File > Preferences:
In the Preferences dialog window, add the following URL to the "Additional Boards Managers URLs" field, then click OK:
https://github.com/stm32duino/BoardManagerFiles/raw/main/package_stmicroelectronics_index.json
Now, click on Tools > Board > Boards Manager:
Select āContributedā type, search for "STM32 MCU based boards" and install:
3.2 Selecting the STM32 microcontroller
After the installation is complete, close the board manager and go to Tools > Board > STM32 MCU based boards.
A list of STM32 MCUs appears, so you can choose between Nucleo, Discovery and Evaluation boards, or generic STM32 MCUs.
By selecting the specific board type, you are able to choose the specific board part number for your board later on.
By choosing the Generic STM32xx Series option, later you are able to select a generic microcontroller for the selected family.
Great! Your board is now correctly selected and recognized by the Arduino IDE!
3.3 Uploading the code
Let us start programming our STM32 device with a simple Blink LED through the Arduinoās IDE.
To perform this task, we have a few options.
These options include programming the STM32 MCU through the Serial Wire Debug, using an STLINK device (external or embedded), and also through bootloader serial port, DFU etc.
Let us see below how to program our STM32 MCU using Arduinoās IDE to get it working properly as expected:
Having the STM32CubeProgrammer installed helps program the STM32 Nucleo, Discovery or Eval board through SWD, Serial or DFU methods with ease. The STM32CubeProgrammer enables drag-and-drop flash programming, so there is no need for a separate debug probe. However, this step is optional and you can program directly via Arduino's IDE as well.
After installing the software and the STM32 cores, go to File > Examples > Basics > Blink:
The Blink LED code pops up in a new window and we can now set the appropriate STM32 board.
After selecting the board type, as we previously made, click again on Tools > Board Part Number > Select the used STM32 device part number:
With the microcontroller correctly selected and the board properly connected, let us define the COM Port where the device is connected. Go to Tools > Ports > Select the Port Number:
Click the Upload Button, wait for the code to be compiled and the board to be programmed:
As we can see, the download is successfully finished!
Congratulations! You have now successfully programed your STM32 device through the Arduino's IDE!
4. Debugging the STM32 over Arduino's IDE
To start a debug session in the Arduinoās IDE, click on Tools > Upload Method > āSerial Wire Debugā option, as follows:
After that, click on the āVerifyā symbol to compile the code and then on the āStart Debuggingā button.
The perspective changes to the Debug Perspective, as follows:
And with all that set, the debug session is up and running!
Note: For more information regarding debug sessions over Arduinoās IDE, you can reach out to Arduinoās documentation over https://www.arduino.cc/.
Hope you enjoyed this tutorial!
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Email to a Friend
- Report Inappropriate Content
I got this error when compling:
Arduino: 1.8.10 (Windows 10), Board: "Nucleo-64, Nucleo L152RE, Mass Storage, Enabled (generic 'Serial'), None, Low/Full Speed, Smallest (-Os default), None, Newlib Nano (default)"
arm-none-eabi-g++: warning: {compiler.optimization_flags}: linker input file unused because linking not done
arm-none-eabi-g++: error: {compiler.optimization_flags}: linker input file not found: No such file or directory
arm-none-eabi-g++: warning: {compiler.optimization_flags}: linker input file unused because linking not done
arm-none-eabi-g++: error: {compiler.optimization_flags}: linker input file not found: No such file or directory
Multiple libraries were found for "SrcWrapper.h"
Used: C:\Users\viict\AppData\Local\Arduino15\packages\STMicroelectronics\hardware\stm32\2.7.1\libraries\SrcWrapper
exit status 1
Error compiling for board Nucleo-64.
Anyone can help me?
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Email to a Friend
- Report Inappropriate Content
It's not very likely that there are Arduino users here.
Try perhaps at https://www.stm32duino.com/.
JW
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Email to a Friend
- Report Inappropriate Content
I'm using an STlinkV2 programmer with an STM32F103C8T6 minimum system development board. While the Arduino IDE (version 2.1.0) recognizes the STlink and allows me to program the board, I encounter an issue when trying to debug. When I click the debug button, I receive the error message: "Request 2 cancelled on connection close." Could you please take a look and let me know what might be causing this issue? Thank you!
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Email to a Friend
- Report Inappropriate Content
You should use latest Arduino IDE 2 version and use latest STM32 core 2.8.x.
Then enable the "Optimize for Debugging" in the "Sketch" menu.
After "upload", click on "Start Debugging" button and it should work.