Skip to main content
JMill.1
Associate III
September 20, 2020
Solved

Preserve a section of FLASH memory during programming

  • September 20, 2020
  • 3 replies
  • 3834 views

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

Modified linker memory definitions:

/* Memories definition */

MEMORY

{

 DTCMRAM  (xrw)  : ORIGIN = 0x20000000,  LENGTH = 128K

 ITCMRAM  (xrw)  : ORIGIN = 0x00000000,  LENGTH = 64K

 RAM_D1  (xrw)  : ORIGIN = 0x24000000,  LENGTH = 512K

 RAM_D2  (xrw)  : ORIGIN = 0x30000000,  LENGTH = 288K

 RAM_D3  (xrw)  : ORIGIN = 0x38000000,  LENGTH = 64K

 FLASH  (rx)   : ORIGIN = 0x8000000,  LENGTH = 1792K

 TABLE   (rwx)   : ORIGIN = 0x81C0000,  LENGTH = 128K

 DATA  (rwx)   : ORIGIN = 0x81E0000,  LENGTH = 128K

}

What we see when programming:

Erasing memory corresponding to segment 0:

Erasing internal memory sector 0

Erasing memory corresponding to segment 1:

Erasing internal memory sector 14

Erasing memory corresponding to segment 2:

Erasing internal memory sector 15

Download in Progress:

This topic has been closed for replies.
Best answer by TDK

You should mark the section as NOLOAD.

https://mcuoneclipse.com/2014/04/19/gnu-linker-can-you-not-initialize-my-variable/

Another option would be to remove the section from your linker file and use a pointer to the user data. This has the benefit of not allowing the compiler to rearrange how it's storing things when you recompile the firmware.

3 replies

TDK
TDKBest answer
September 20, 2020

You should mark the section as NOLOAD.

https://mcuoneclipse.com/2014/04/19/gnu-linker-can-you-not-initialize-my-variable/

Another option would be to remove the section from your linker file and use a pointer to the user data. This has the benefit of not allowing the compiler to rearrange how it's storing things when you recompile the firmware.

"If you feel a post has answered your question, please click ""Accept as Solution""."
Tesla DeLorean
Guru
September 20, 2020

If there is data for the section in the .ELF, the tools will probably try to rewrite.

Use a NOLOAD / NOINIT section for stuff you don't want data in the .ELF / . AXF file.

Have your app write usable defaults, if you have multiple devices to debug, have a table driven by the unique ID

Keil doesn't write to unused sectors, it is a checkbox item in the debug/flash options

Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
JMill.1
JMill.1Author
Associate III
September 20, 2020

Thanks, to both of you. Adding (NOLOAD) was all it took. Learned something new today!

Cheers.