How to connect to the STM32 Nucleo board?

Michał Balicki Avatar by Michał Balicki
on April 3, 2022

Hello

As I mentioned in the previous post, I had the opportunity to attend Arduino & Raspberry Pi Day 2022 as a lecturer. My presentation was about a practical introduction to bare-metal programming with the use of STM32. It contained a theoretical and practical part. Link to the presentation is here. It took me some time to prepare the topic. During its creation, I created material for 2-3 posts about embedded programming. In today's post, I would like to discuss the topic of connecting to Nucleo boards from the command line using OpenOCD. At the very beginning, I will introduce you to what OpenOCD is. In simplified terms, we can say that it is:

“ OPENOCD IS A FREE APPLICATION THAT CAN BE RUN ON THE HOST SIDE. PROVIDES JTAG/SWD ACCESS FROM GDB. WITH ITS USE, IT IS POSSIBLE TO PROGRAM OUR TARGET PLATFORM.”

In this case, the host is a fast machine e.g. our PC, on wich we compile our project. We run OpenOCD on it in order to connect to the target(Nucleo board). The figure below illustrates the split into host and target:

Before we move on to the connection to the board, we need to list the things we need:

Having the above mentioned things, we can start trying to connect the board via the USB port. If the programmer was detected correctly, the st-info --probe command should have confirmed it, as in the example below:

If the programmer has been detected, we can try to connect to the board. I use Linux Mint on a daily basis. After installing OpenOCD, all configuration files for the various platforms are in usr/share/openocd/ scripts/board/ directory. In the case of Nucleo-STM32F103RB, we are interested about st_nucleo_f103rb.cfg file. Below is an attempt to navigate to the directory and find the required configuration file:

As you can see, we have a lot of files for different platforms. Being in this location, we can try to connect to the board. The command is: openocd -f cfg_file. Below is an attempt to use it:

Such an output after its use indicates a succesful connection. This is shown to us by the last line, which is Info : stm32f1x.cpu: hardware has 6 breakpoints 4 watchpoints. The number of breakpoints and watchpoints may be different, depending on the core we use. For the Nucleo-STM32L053R8 with Cortex-M0+ core, these numbers may be different, but in general the presence of this line indicates a correct connection with our platform.

In the next posts, I am going to introduce the compilation theory and try to illustrate the process by preparing firmware for the green tea thermometer project. We will compile the source code from the command line and then try to upload it to the microcontroller.


You Might Want To Read...
Fishing Fishing summary for 2023 and plans for 2024

House Building a house - the next stage of work

General How is it going?