cancel
Showing results for 
Search instead for 
Did you mean: 

Placing variables in dedicated part of memory.

SSmit.13
Senior

Hi

  I'm using a STM32L433 in a battery application, and running in Stop mode. I want to keep some variables in RAM2 so their values are not lost when the processor is woken up.

I managed to get it working as follows. I created a block in the linker file called ".Permanent_buffer ", then initialised a block of memory to fit in it, see below at bottom.

I will have a few variables working this way, and wondering if there is a way I can assign the start all variables in RAM2, for example ( I havent a clue how to do this, just to show what I mean):

#define .Permanent_buffer

int PermA=1; //will keep value on STOP 

long PermB=2; //will keep value on STOP 

#endif

int TempA=3; //will loose value on STOP

long TempB=4; //will loose value on STOP 

This way it would save me adding __attribute__((section(".Permanent_buffer"))) one each variables. Is there a way to do this?

 

Many thanks

Scott

 

Code I have working.......

 

typedef struct{

long sig;

long date;

long time;

short int hum;

short int temp;

}Results;

 

char PermanentBuff[sizeof(Results)*500] __attribute__((section(".Permanent_buffer")));

Results *ResPtr=(Results *)&PermanentBuff[0];

 

 

Linker file:

.Permanent_buffer :

{

KEEP(*(.Permanent_buffer))

} >RAM2

 

 

4 REPLIES 4
Johi
Senior III

See

https://stackoverflow.com/questions/44443619/how-to-write-read-to-flash-on-stm32f4-cortex-m4/44855815#44855815 

And you can still use a

#define perm __attribute__((section(".user_data")))

If you want to get rid of the __atrribute__ blablabla :)

Best regards,

Johi.

Hi Johi

  The link doesnt go anywhere, can you please check the web site?

 

Best Regards

Scott

TDK
Guru

You can't do this unless you also modify the startup script to initialize those values, or initialize them somewhere else in your code.

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