Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I generate a binary file of the stm32 code?

I am building a firmware updater for an STM32 MCU. I have so far programmed bootloader software on the device, separate from the main application in FLASH.

What I need to do is generate a binary file which will be the replacement code for the main application in FLASH. This means I can transfer the file over UART and overwrite the main application. How do I go about producing such a file?

The code was programmed using the stm32CubeIDE which generates an .elf file after building. I will add a header to this binary code before transmitting over UART.

Thank you very much in advance for your help,

Harry

like image 948
arry_h Avatar asked Oct 29 '25 16:10

arry_h


2 Answers

In CubeIDE go to Project Settings -> "C/C++ Build" group -> Settings -> "Tool Settings" tab -> MCU Post build outputs -> "Convert to Intel Hex file" check box Hex file option in CubeIDE (If you do not see those options, you may need to restart the IDE - such a bug still exists)

This will make the IDE convert the output into HEX-file, which is easily parsable. You can find the format description in Wikipedia. You can parse it before sending to the bootloader.

Or, you can set the checkbox "Convert to binary file", which will make a raw binary file. But it may give some troubles if your code starts not from zero address.

like image 123
AterLux Avatar answered Oct 31 '25 08:10

AterLux


You will want to use the objcopy.exe that comes with your IDE. The following works with Atollic TrueStudio, the predecessor to STM32CubeIDE. This step is usually added as a post build step

arm-atollic-eabi-objcopy.exe -O ihex "${BuildArtifactFileBaseName}.elf" "${BuildArtifactFileBaseName}.hex"

For more info on objcopy: https://sourceware.org/binutils/docs/binutils/objcopy.html

like image 38
abonneville Avatar answered Oct 31 '25 06:10

abonneville



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!