cancel
Showing results for 
Search instead for 
Did you mean: 

RAM retention between resets.

EMich
Associate II

Hello,

How do I retain a RAM section from bearing filled with '0' between resets.

Suppose I have a pointer to 256 bytes buffer that I'd like to preserve between resets (as long as the power was not disconnected), could you please guide me, step by step. to what needs to be done?

Thanks,

Eitan.

2 REPLIES 2
Danish1
Lead II

With C, as you have observed the standard behaviour is that variables are initialised to 0 at startup.

In most development environments for embedded systems, you can specify not to do this for specific variables. You do not state *which* development environment you are using, and I don't know how to do it in the latest favourite stm32Cube.

In my preferred development environment (Rowley Crossworks) I have to tell the compiler to put the variable into a memory section that doesn't get loaded; I like to call it "persistent". Normally there isn't such a memory section so I have to create one, the key feature being load="No". So I add the following line to the section-placement file for my project.

  <ProgramSection alignment="4" load="No" name=".persistent"/>

And then any variables I want to keep over reset have to be put there. In the C or C++ file, where the variable is defined I need to add an attribute to say the variable is persistent. For example I pass a result from my bootloader to my main application, so the application can put into the log if firmware was updated or whatever:

#define PERSISTENT __attribute__((section(".persistent")))

volatile int theBootResult PERSISTENT;

It will be different depending which development environment you use. But the basic idea is the same.

Oh and for things that are expected to persist over firmware upgrades, you'll want to put the persistent stuff at a place that doesn't move as you add more variables, so probably *before* all other variables in the section-placement file.

Please let us know the development environment / IDE you use. Then someone can give more specific help.

Hope this helps,

Danish

TDK
Guru

The NOLOAD directive can be used in a linker file to specify not to load that section.

Among other hits:

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

If you feel a post has answered your question, please click "Accept as Solution".