2018-03-11 11:25 PM
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-flash2018-03-12 02:59 AM
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
2018-03-12 07:52 AM
,
,
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 ?
2018-03-12 08:37 AM
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.
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.
2018-03-12 11:45 PM
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.