cancel
Showing results for 
Search instead for 
Did you mean: 

generate binary file for flash to write constant values

ismail fatih iltar
Associate II
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
4 REPLIES 4
David SIORPAES
ST Employee
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

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 ?

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.

Posted on March 13, 2018 at 06:45

my program starts from sector 0 and it goes up to sector 5. so my sector 7 is completely free. i will add it . i will try 

objcopy.exe. Thanks a lot for your detailed answer David.