Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
5 years, 5 months ago.
How can I retain static global variables on reset??
I need to be able to retain some variables on soft reboot and WDT timeout reset.
How can do this?
Doing the below results in backupCounter being 0 on every reset!?
uint32_t* backupCounter = (uint32_t*)0x20003000UL; or whatever ram address you want to use
main () {
- backupCounter ++
}
Thanks
1 Answer
5 years, 5 months ago.
Hello Ben,
You can try mbed's new NVStore module.
Thanks for this, have just tried NVStore, very good. The issue I have is that i really want to store this data in RAM, to save on writes. Or does NVStore manage wear?
posted by 24 Oct 2018Sorry but I have no idea how to retain RAM on reset. I think NVStore is trying to reduce wear:
- It uses two flash areas, active and nonactive. New values are added to the end of the existing data in the active area superseding the previous value that was there for the same key (means it does not write them to the same location).
- When the active area becomes full, garbage collection is invoked. This compacts items from the active area to the nonactive one and switches activity between areas.
This will be very part specific. Your best bet is to look in the user manual for the CPU you are using to see if there are any memory locations that are maintained through a reset.
posted by Andy A 23 Oct 2018