2023-08-31 10:53 AM
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
2023-08-31 11:47 AM - edited 2023-08-31 11:47 AM
See
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.
2023-08-31 12:44 PM
Hi Johi
The link doesnt go anywhere, can you please check the web site?
Best Regards
Scott
2023-08-31 01:03 PM
2023-08-31 01:39 PM
You can't do this unless you also modify the startup script to initialize those values, or initialize them somewhere else in your code.