0
votes

Following in the directions of this post, I am able to reserve and write to (and read back) from a section of FLASH dedicated to calibration data.

Problem:
However, when I reprogram the device, the IDE wipes the whole memory clean before programming and we lose all the data. Since we are in a debugging cycle, we are constantly reprogramming and have to write the calibration back as a first step every time.

Is there a way to tell the IDE to only erase a certain region of memory corresponding to the program data? Thanks.

1
AFAIK you can do that by modifying the linker script accordingly (leave the wanted flash area untouched), and making sure that the programmer / IDE uses the right programming commands, I can only talk about OpenOCD used with an ST-LINK/V2 here: the program command writes the ELF & automatically erase the required memory, see also: openocd.org/doc/html/Flash-Programming.html#Flash-Programming, but you have pretty much full control over what's happening to the flash via different commands: openocd.org/doc/html/Flash-Commands.html#Flash-Commands / write to RAM is possible too BTWrel
...and if you only want to write data (e.g. calibration data), you can omit the IDE completely and write the image to the target's flash memory with a simple shell script, that executes the programming commands (and also write protects the area afterwards), in the case of OpenOCD, see: flash erase_sector num first last / stm32f4x unlock 0 / flash protect 0 0 last off / flash write_image [erase] [unlock] filename [offset] [type] and similar commands in the docs.rel
Thanks @rel. You are essentially correct - linker file needs to be alerted to these sections and told to leave them alone. Details are in my post below.walkingcrane

1 Answers

1
votes

The ST Community came to my aid. Answer is to use (NOLOAD) in the linker file to tell the compiler not to put initialization data in the .elf file. Details can be found here: https://mcuoneclipse.com/2014/04/19/gnu-linker-can-you-not-initialize-my-variable/