简体   繁体   中英

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

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

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 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.

对于 STM32CubeIDE 的内部构建器,这工作得很好(作为构建后步骤):

arm-none-eabi-objcopy -O ihex ${ProjName}.elf ${ProjName}.hex

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM