Skip to main content
ismail fatih iltar
Associate III
March 12, 2018
Question

generate binary file for flash to write constant values

  • March 12, 2018
  • 1 reply
  • 1249 views
Posted on March 12, 2018 at 07:25

Hi, i want to add some constant values (etc. MAC ) to specific flash sector address while programming mcu (stm32f7) with stlink. i must combine my program binary with constant value binary than i will load it to mcu. in sw mcu will read the specific sector to get mac address. this is my plan. How can i do it ? How can i combine binaries ? or another way ? Thanks  

#flash-programming #flash-sector #external-value-to-flash
This topic has been closed for replies.

1 reply

David SIORPAES
ST Employee
March 12, 2018
Posted on March 12, 2018 at 10:59

You could use objcopy to add a new section to your elf file as follows:

arm-none-eabi-objcopy.exe --add-section .macdata=mac.bin --set-section-flags .macdata=load,alloc  --change-section-address .macdata=0x08004000 original_file.elf new_file.elf

where mac.bin is the binary file containing your data and 0x08004000 is the address you want to place it.

If using IAR you could just use #pragma location

ismail fatih iltar
Associate III
March 12, 2018
Posted on March 12, 2018 at 14:52

 ,

 ,

David Siorpaes wrote:

You could use objcopy to add a new section to your elf file as follows:

 ,

arm-none-eabi-objcopy.exe --add-section .macdata=mac.bin --set-section-flags .macdata=load,alloc , --change-section-address .macdata=0x08004000 original_file.elf new_file.elf

 ,

where mac.bin is the binary file containing your data and 0x08004000 is the address you want to place it.

 ,

If using IAR you could just use ♯ pragma location

Thank you David. arent there all sectors at program original elf file ? for example i will add sector 7 to MAC address. , in your command as i understand it will add a section , to original elf. , what if my original elf still has this sector ?

David SIORPAES
ST Employee
March 12, 2018
Posted on March 12, 2018 at 15:37

The elf file has no knowledge of flash sectors. Elf only contains information how the application is laid out in memory. The application loader will then use this information to place the correct sections in the proper flash addresses and will take care about flash sectors erase/write operations.

You only need to make sure that your extra section does not overlap with your application code. In this snapshot you see for example that the ER_IROM1 section produced by the toolchain starts at 0x08000000 and its size is 0x108c. The extra section that I added '.macdata' starts from 0x08004000 and has size of 0x0a.

0690X0000060A4qQAE.png

Note however that you can also use ST-Link to flash specific files to specific addresses so you can avoid ''combining'' the two files if you wish.