ST-Link Utility can program .hex and .bin files. These are automatically generated by the ARM gcc Makefiles provided with the TouchGFX project. The IAR and Keil IDE's are configured to convert the output .elf files to a .hex file.
- For IAR projects, additional output is converted (
intel extendedformat) to
- For Keil projects, the following post-build step is executed:
fromelf --only=ExtFlashSection --bin --output=binary .\Objects\keil5-2.axf
resulting in a .hex file:
Flashing using ST-Link Utility GUI
The process described in this article outlines how to use the ST-Link Utility to program the internal and external flash of the ST boards. For the internal flash, ST-Link will automatically detect the type of device connected. For an external flash, however, an external flash loader must be configured manually. ST-Link offers support for every flash chip found on boards supported by TouchGFX.
When you flash a binary file using ST-Link Utility, you must supply the correct flash address manually. This address must match the address used in the linker script. The default is the first address in the flash. When flashing a .hex file, ST-Link Utility will find the correct address in the .hex file.
ST-Link will automatically detect the memory ranges to program and select a suitable flashloaders to use, if so configured, when opening a .hex-file. In the example below,
target.hex for an application was opened in ST-Link and ranges from both internal and external flash were detected.
[target.hex] opened successfully. Address Ranges [0x08000000 0x08010364] [0x90000000 0x9000CA28]
As mentioned previously, the internal flash is always recognized by ST-Link for STM32 MCUs, but the flash loader for ranges starting at 0x90000000 must be configured manually. In the example below, we’ll configure the external flash for the
- Select “Add External Loader” from the “External Loader” menu.
- Select the appropriate flashloader in the list of supported boards (i.e.
STM32F746G-DISCO) and select Validate.
- Open the .hex you wish to flash: The address ranges are automatically detected by ST-Link. As previously mentioned, different binaries are produced by IAR, Keil and gcc, respectively, and can be used by ST-Link.
- Select “Program” from the “Target” menu, and initiate the download.
make (ST-Link CLI)
Additionally, you can build and flash an application (using ST-Link CLI) through any
app/example/button_example/target/ST/STM32F746G-DISCO/gcc/Makefile) using the following command:
$ make flash
The makefile knows which external flash (refer to table above) to use for each of the supported ST boards. ST-LINK has built in support for the internal flash for each board and you can flash just the internal flash by using the following command:
$ make intflash
You may, on occasion, be unable to program your board using the above method, due to the following error:
STLink USB communication error Error during erase operation.
In this event, you may try to disable the USB device driver for that particular board in Windows Device Manager to fix the issue.
Read more about ST-Link Utility here.