This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Trying to restore app state from brown-outs or power loss

We're trying to make our device automatically recover after a brown-out or brief power loss.  I'm hoping to leave a system-state value in a RAM location and check for it on boot-up. 

Is there a persistent register I can use to store a state value between resets?  The GPREGRET registers are cleared on a hard reset.  I believe RAM is all zeroed on boot-up.  Or is there a way to prevent some RAM locations from being reset during the start-up process?

I could store the app state in the FDS, but I feel like that would thrash the FLASH over the product's life cycle.  Starting the FDS also requires substantially booting the system.  That hurts our power budget.

I'm using the Segger toolchain.

Thanks!

  • Hi,

    Is there a persistent register I can use to store a state value between resets?  The GPREGRET registers are cleared on a hard reset.  I believe RAM is all zeroed on boot-up.  Or is there a way to prevent some RAM locations from being reset during the start-up process?

    RAM is not cleared upon reset, this task is done by startup initialization code. You can put your system state into non-initialized section, as described here. One cannot be sure that RAM is not corrupted even after a short power loss, so you need to add some CRC to your state area.

    I could store the app state in the FDS, but I feel like that would thrash the FLASH over the product's life cycle.  Starting the FDS also requires substantially booting the system.  That hurts our power budget.

    What's the size of your state data? How often should it be updated? You can write the state directly using NVMC - for example, having 4-byte state and one-sector storage space, you will need only one erase operation per 1024 updates. Also, there's no need to initialize FDS in this case, you can use binary search to find last written entry very quickly.

Related