on 2022-12-18 02:35 AM
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.
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 .
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.
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..
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.
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.
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.
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.
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.
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:
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:
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:
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:
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:
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:
As 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).You 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:
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’ :
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:
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:
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:
STM32CubeProgrammer User Manual: https://www.st.com/content/ccc/resource/technical/document/user_manual/group0/76/3e/bd/0d/cf/4d/45/25/DM00403500/files/DM00403500.pdf/jcr:content/translations/en.DM00403500.pdf
STM32CubeProgrammer page:
https://www.st.com/en/development-tools/stm32cubeprog.html
Programming STM32 MCUs using STM32CubeProgrammer video series:
https://www.youtube.com/watch?v=WY1hQzMh6wo
Connect and run STM32CubeProgrammer is a simple step by step from:
Update your ST-LINK probe firmware if needed.
Connect your ST-LINK probe to STM32CubeProgrammer
This will update the Memory & File edition view
You can read the entire or parts of the memory
You can program the memory using a binary file
You can erase the entire STM32 memory