STM32CubeProgrammer is a powerful tool with many useful functions for programming and debugging STM32 devices. Its sophistication, however, introduces a moderate learning curve which may frustrate first-time users who just wish to perform a simple programming task. That is, its not immediately obvious how to use the tool to program the internal flash memory of an STM32 device with the contents of a given executable/binary image file (e.g., .elf files, .hex files, and .bin files). In fact, there are multiple ways to accomplish this task. The following tutorial demonstrates what’s arguably the simplest method for those wishing to get started quickly.
This tutorial utilizes the latest version (version 2.12.0 at the time of writing) of STM32CubeProgrammer. It describes a very common and basic operation which shouldn’t require changing any of the application’s default settings. Those with more advanced use cases who wish to learn more about these settings and/or the higher capabilities of the tool should review the STM32CubeProgrammer User Manual (UM2237).
Connect the ST-LINK probe to the PC with an appropriate USB cable. If you are working with an STM32 Nucleo, Discovery, or Eval kit; the ST-LINK is embedded on the board and there should be a USB port labeled “ST-LINK”, “STLK”, or similar (see Figure 1). See the user manual for your board if you’re not sure which connection to make.
Open the STM32CubeProgrammer application. On the right-hand side, “ST-LINK” should by default be selected as the target interface in the target configuration panel (shown in Figure 2). Leave the connection settings at their default values and click the green Connect button. The board should connect successfully.
Figure 2: Connecting to an STM32 development board using the default ST-LINK interface.
Click on the + tab and choose “Open File” as demonstrated in Figure 3. Use the file browser to choose the file you wish to be programmed to the board. The file formats supported by STM32CubeProgrammer are binary files (.bin), ELF files (.elf, .axf, .out), Intel hex files (.hex) and Motorola S-record files (.Srec).
Note: If you select a binary (.bin) file as the source file, you must specify the download address by clicking the drop-down arrow next to the Download button and supplying the starting address in the Address field (see Figure 4a). If you select another file type (e.g., .elf or .hex), the Address field in this drop-down menu is grayed out and cannot be modified (see Figure 4b).
a) The opened file is a binary file
b) The opened file is not a binary file
Figure 4: The Address field is modifiable if the opened file is a binary (.bin) file.
Click the Download button to begin programming, as shown below in Figure 5.
Once the STM32 MCU programming is complete, click OK to close the message box and click the green Disconnect button as indicated in Figure 6. You may have to press the Reset button on the development board to start the application.