HOW TO KEEP VARIABLE IN RAM AFTER EXIT FROM VLLS3

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

HOW TO KEEP VARIABLE IN RAM AFTER EXIT FROM VLLS3

Jump to solution
1,824 Views
isaacromero
Contributor II

I am trying to store some variables in memory before entering VLLS3, I suppose all the "memory" is restored like if I was making a hard reset in this stage. Is there any way to store some data before entering VLLS3? and then restore it in RUN Mode, if this is possible, how can I achieve that? 

1 Solution
1,430 Views
mjbcswitzerland
Specialist V

Hi

1. Linker script file set to start at the beginning of SRAM and end at x bytes 'before' the end of SRAM. Now the last x bytes will be reserved (never used/initialised).

2. To save data to this area:

PRESERVED_DATA *ptrData = (PRESERVED_DATA *)0x20003490; // set a struct pointer to the area (assumed to start at 0x20003490)

PRESERVED_DATA struct can be defined as one likes to make variable access simple.

3. When you know that the last reset was due to a power cycle (check the value in the reset controller to identify this), reset it with something like:

if (power cycle occurred) {
    memset(ptrData, 0x00, sizeof(PRESERVED_DATA));
}

4. Write data to it

ptrData->variable1 = 0x1234; // for example

5. Reset the board (software reset)

6.
PRESERVED_DATA *ptrData = (PRESERVED_DATA *)0x20003490;
if (ptrData->variable1 == 0x1234) {
    printf("Hey, it works!!");
}


It is as simple as that and doesn't need to be restricted to particular API libraries.

Regards

Mark

View solution in original post

3 Replies
1,430 Views
mjbcswitzerland
Specialist V

Hi

All RAM content is retained in VLLS3 but to exit and return to RUN mode it needs to pass through a reset.
The RAM content is not modified during this process (assuing that any internal ROM loader is disabled) so any areas of SRAM that are not re-initialised by the software's initialisation sequence will still retain their values.

A simple method of keeping an area in SRAM that is untouched by the software initialisation and subsequent operation (for storing variable to be retained) is to set the stack pointer (usually at the top of SRAM) to a lower location so that anything above its initial value will never be used during normal operation.

Regards

Mark

Kinetis: http://www.utasker.com/kinetis.html
FRDM-KL43Z: http://www.utasker.com/kinetis/FRDM-KL43Z.html
FRDM-KL27Z: http://www.utasker.com/kinetis/FRDM-KL27Z.html
Low Leakage Wakeup: http://www.utasker.com/kinetis/LLWU.html

1,430 Views
isaacromero
Contributor II

Hi 

About this solution, sounds good, but if I declare a variable which will be store in the higher position of the SRAM, when returning to RUN, the space of these variables will be re-assigned and the saved data will be lost, so do you know the way to write & read in specific space of memory? Is there any function?

Actually I´m using "Kinetis SDK 2.0 API Reference Manual".

Regards. Isaac Romero

0 Kudos
Reply
1,431 Views
mjbcswitzerland
Specialist V

Hi

1. Linker script file set to start at the beginning of SRAM and end at x bytes 'before' the end of SRAM. Now the last x bytes will be reserved (never used/initialised).

2. To save data to this area:

PRESERVED_DATA *ptrData = (PRESERVED_DATA *)0x20003490; // set a struct pointer to the area (assumed to start at 0x20003490)

PRESERVED_DATA struct can be defined as one likes to make variable access simple.

3. When you know that the last reset was due to a power cycle (check the value in the reset controller to identify this), reset it with something like:

if (power cycle occurred) {
    memset(ptrData, 0x00, sizeof(PRESERVED_DATA));
}

4. Write data to it

ptrData->variable1 = 0x1234; // for example

5. Reset the board (software reset)

6.
PRESERVED_DATA *ptrData = (PRESERVED_DATA *)0x20003490;
if (ptrData->variable1 == 0x1234) {
    printf("Hey, it works!!");
}


It is as simple as that and doesn't need to be restricted to particular API libraries.

Regards

Mark