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

RAM data is retained without power?

SDK: 17.0.2

IDE: SES

nRF52832 module

Hi!

I have a nRF52832 based custom board operating on battery power.  I assigned a variable to the non_init section in SES and loaded a value.  I expected this would disappear if I disconnected power, so I unhooked the battery and powered off the connected nRF52 DK.  And I closed SES.  Then I powered up everything and ran the debugger to the point where I read my non_init variable from RAM.  It still had the data I wrote!  What gives?  Shouldn't this value have disappeared when powered down?

So I thought I would leave a few hours  go by in case there was a cap holding the RAM data active.  After something like 4 hours I still read the the value I wrote into the non_init RAM.

What I'd like to do is have some method to detect an initial power on reset state after connecting power and set some initial conditions for the application that will be used as long as power is on .... such as date and time.  Let me know if you can suggest a good way to do this.

Thanks!

Max

    

Parents
  • What I'd like to do is have a variable be set to zero (or some value) on initial power up.  Then on initialization I could look to see if it's telling me this is an initial power on startup.  I'd then execute some code that I want to ONLY be run once on power on.  I thought to do this I would declare the variable to be in the .non_init segment and have my initial power on code write some known value in it which would not change with any subsequent resets and initialization and would be kept as long as power was on (i.e. my battery has not expired).  I was surprised to find that once I wrote a value into my .non_init variable, unplugging the battery did not cause that value to disappear.  

    I thought the GPREGRET registers might work for this, but I plan to have DFU and that uses them.

    I suspect this might be done with a modification of the Segger section placement file plus perhaps some code to define the initial state of the .non_init RAM section and load it.  I can't claim I know what I'm doing there though and would take a while to figure it out.

  • This works well, and is only invoked if RAM was lost on a power loss or other first-time power-up situation:

    // One-time unique key, Use for example unique device ID as the valid signature
    static volatile uint32_t mIamInitializedRTC __attribute__((section(".non_init")));
    
        // See if RTC data is valid - Use unique device ID as the valid signature
        if (mIamInitializedRTC != NRF_FICR->DEVICEID[0])
        {
           // Key not valid, perform the 0ne-time initialisation
           ClearRTC_Timers();
           // Indicated data is now valid - Use unique device ID as the valid signature
           mIamInitializedRTC = NRF_FICR->DEVICEID[0];
        }

    I use this on nRF52832 and nRF52840 with no issues. The section placement file already handles the non_init section unless you are using a modified file.

      <MemorySegment name="RAM" start="$(RAM_PH_START)" size="$(RAM_PH_SIZE)">
        ...
        <ProgramSection alignment="4" load="No" name=".non_init" />
        ...
      </MemorySegment>

  • Thanks!!!

    I'm going to give this a try and see if I can work it in to my application.  May take a day or 2.  So far what you presented above compiles.  Some additions for the one time code and testing to follow.  I'll report back.

    Yes, I am using the standard section placement file .... hopefully I'll be OK with that. 

    Max

Reply Children
No Data
Related