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