cancel
Showing results for 
Search instead for 
Did you mean: 

How can I connect to my STM32 evaluation board using STM32CubeProgrammer

How can I connect to my STM32 evaluation board using STM32CubeProgrammer?

1. What is STM32CubeProgrammer?

STM32CubeProgrammer is our standalone software tool that can automate STM32 programming via a very easy graphical or command line interface. The tool can also be used to read and configure Option bytes.

This tool supports programming operations through various supported debug and bootloader interfaces..
You can program, read or erase internal and external memories connected to your STM32 Microcontroller using this tool.
 

2. Introduction

In this first article, we will cover some of the views and functions of the STM32CubeProg, such as the configuration panel, and the memory view; we will interact with them to see how we can do basic memory operations using a NUCLEO-G0B1RE.
Although the example is using the NUCLEO-G0B1RE, you can use the same steps for other STM32 based boards. The main differences are usually the ST-LINK interfaces we have in each of those,  so it is recommended that you check your board’s user manual for those details.
This article will start by connecting to the NUCLEO-G0B1RE, with a walk through of the different ways we can connect to the same board, and also using an external debugger such as ST-LINK V3 to connect .

 

3. Getting to know the views

844.png

This is the first view you have when you open the STM32CubeProgrammer with a NUCLEO-G0B1RE connected to your computer.

3.1 ST-LINK configuration view

On the top right you should see the ST-LINK Serial Number, this is the ST-LINK present in the NUCLEO-G0B1RE board. Every ST-LINK has a unique serial number, which allows you to connect more than one board to your computer and choose the one you would like to connect; use the drop down box, and select the right ST-LINK corresponding to your target.

3.1.1 Port 

After that we have the port drop down box, here we can choose between the different ports we can connect to our STM32 target microcontroller; in our case we are using SWD, since this board has an STM32G0B1, which is an ARM Cortex-M0+ core that only supports SWD; If we were using a different MCU, like STM32H7 with a Cortex-M7 core, we can choose between SWD and JTAG as both are supported by that core..

3.1.2 Frequency

Talking about speed, the third dropdown box is the frequency (kHz), this should offer several options based on the interface we are using, in this case we can go from  5 to 4000 kHz.Since we are using 2-pin SWD, this is slower compared to 5-pin JTAG. Sometimes, when you have a poor EMI design that causes issues during programming, you can slow down this frequency to create a safer connection between the ARM-Cortex core and the debug interface.

3.1.3 Mode

The next dropdown is the Mode, this lets us choose between some important options on how to connect to the core at the beginning of the session. , You may have an application that has Low Power enabled, the debug interface is powered off, which can prevent a successful connection; , Or, we could an application running and we don’t want to reset the core during the connection.
The most reliable option is the last one “under reset” that holds the device under reset while making the connection.

3.1.4 Access Port

Next one is the Access Port, this one will almost always be 0, since almost all of our STM32 devices just have only one port, that is the port 0, but this will be the access port you will use to access the ARM-Cortex Core through the Jtag interface.

3.1.5 Reset Mode

Together with the mode, the Reset Mode dropdown box is one of the most important options when you’re trying to connect to an application that is already running and couold be in low power mode or other pin configuration; here, you can chose the behavior of the reset when the debug interface is trying to connect to the ARM Cortex Core: you can choose between Software system reset, that will reset all STM32 components except the Debug via the Cortex-M application interrupt and reset control register (AIRCR), the hardware reset that will reset the STM32 device via the nRST pin (it’s important to mention that for that the RESET pin of the JTAG connector (pin 15) must be connected to the stm32 microcontroller reset pin to use this configuration, otherwise it will not work) or the core reset that will resets only the Cortex-M via the AIRCR.

3.1.6 Shared

The next dropdown box is "Shared”, which will be very useful when you have to read memory and debug or grant access to two different platforms such as STM32CubeIDE and STM32CubeProgrammer; enabling this option will grant access to the ST-Link probe from other hosts.
Just below, we have a small check box “Debug in Low Power mode”, which could be very useful together with Mode and Reset Mode;  this one grants us debug capability in some STM32 series such as STM32L4, STM32WB and STM32U5.Some of the STM32Cube example projects have this feature enabled, so when running those examples, this option is something we will need to enable.
Other than that we have now some information regarding the Target microcontroller, the board and the ST-LINK itself; Target voltage is the target STM32 microcontroller voltage at the VDD pin, Firmware version is the ST-LINK firmware version.The Target information view will be updated with the target STM32 Microcontroller information after a successful connection is established.

 

4. Firmware Upgrade – Step by step

One of the most important steps when connecting to your STM32 Microcontroller board over an ST-LINK probe is make sure that your ST-LINK firmware is up to date;  
Here we have a button where you can update your ST-LINK probe firmware, as simple as it appears.
Clicking on it will open a STLinkUpgrade tool window, this will show some options we will need to check:

 

845.png
  • First, we will need to check if the dropdown box shows the version/model of our ST-LINK probe correctly, since we are using an NUCLEO-G0B1RE this should be an ST-LINK/V2-1.

  • Second, it’s important to check (again) if the ID is the correct ID of the ST-LINK probe we want to update, in case we have more than connected to our computer.

  • Then, click on Open in update mode, which will put our STM32 Microcontroller in the ST-LINK probe in Bootloader mode, so we can update its firmware.

  • You should hear a notification sound from your operating system, and the window will be updated with the ST-LINK firmware version information, something like this:

846.png

Here we will be able to change the type, if we want to change between STM32 Debug+Mass storage+VCP or STM32 Debug+VCP only, which will enable or disable the drag and drop feature to update the firmware in our NUCLEO-G0B1RE board.
After that, if we have an older version of the firmware, we can click on the Upgrade button to update our ST-LINK probe firmware:

847.png


After the loading bar completes its progress, we will hear another Operating system notification sound and the window will be updated with an Upgrade Successful message on the bottom:

848.png

5. STM32CubeProgrammer – step by step demo

 

Now that we launched the STM32CubeProgrammer , selected our NUCLEO-G0B1RE board and made sure that our ST-LINK probe firmware is updated, we can go over the memory interactions. Click on the green Connect button at the top right of our window.
The entire Memory & File edition view will be updated, this will show us the memory address and the content at those addresses, like this:

849.png
Now we are connected, and we can read, write or erase this STM32G0B1 microcontroller.
Let’s read some addresses where we can find something to check. In this STM32G0 series, we have the Unique device ID register at the base address: 0x1FFF 7590, this is the same ID we can see on the right side of STM32CubeProgrammer window, so If we type this address in the Address box on the top left side of the Device Memory view we will be able to confirm that; after typing the address, make sure that the size and data are set to appropriate values you want.
Since we want to check an ASCII number, lets use Size 0x400 and Data Width 8-bit, then click on the blue “Read” button on the right side of the same panel, you’ll see something like this:

850.pngAs you can see, on the 7th, 6th and 10th data we have the same ID we can see on the Target information (in ascii) 0x34 0x36 0x37 that is 0x467.

This same process can be done to read any memory inside your STM32 microcontroller (Flash, RAM, EEPROM, Option Bytes).
  • Now, to program something in the microcontroller memory from an elf file, you can use the same window view; Just click on the Open File tab on the top of your screen, this will open your operating system file explorer, choose an elf that is compatible with your target STM32 microcontroller, then click on Open, in the same file system explorer window.
  • The view will then change a bit, showing the elf file you chose and what will be flashed in the memory address view, something like this:

851.pngYou will now notice that we have a different option at the top right blue button, labeled “Download”.
When we click on that the loading bar will show progress as the firmware is downloaded to our target STM32 microcontroller and after that a File download complete window will appear showing us that the process is complete:

852.png

Another useful feature inside STM32CubeProgrammer is to verify if the firmware inside an STM32 is the same as a file, to guarantee the integrity of firmware versions, for example.
To do this, you just need to go to the right dropdown arrow on the download button and chose Verify. When you do that, the STM32CubeProgrammer will compare the elf file opened in its view with the memory inside the target STM32 Microcontroller connected to it. If it didn’t find any difference between the memory and the file, you will see a message showing ‘Verification successfully done, no data mismatch found’ :

853.png


To finish this article lets erase this STM32G0B1 memory. To do that we will need to look towards the bottom left and find the eraser icon: 

854.png
When you click on the Full chip erase the entire flash memory of the target STM32 microcontroller will be erased, so a pop-up will appear and ask if you really want to do that:

855.png


After that, a successful message will appear and we are done, the entire target flash memory was erased.
We can confirm that looking into its Memory & File edition view:

856.png
After doing all the interactions, don’t forget to click on the green button on the top right, which should now be labeled “Disconnect”.

6. Useful links

https://www.st.com/en/development-tools/stm32cubeprog.html
 

  • Programming STM32 MCUs using STM32CubeProgrammer video series:

https://www.youtube.com/watch?v=WY1hQzMh6wo

7. Conclusion

Connect and run STM32CubeProgrammer is a simple step by step from:

  • Connect your board/ST-LINK probe to your computer and make sure that it is listed on the STM32CubeProgrammer ST-Link Configuration panel.
  • Update your ST-LINK probe firmware if needed.

  • Connect your ST-LINK probe to STM32CubeProgrammer

    1. This will update the Memory & File edition view

    2. You can read the entire or parts of the memory

    3. You can program the memory using a binary file

    4. You can erase the entire STM32 memory

  • Disconnect and enjoy your application.

 

Version history
Last update:
‎2022-12-18 02:35 AM