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

how can I retain RAM after watchdog reset and bootloader present

Im using nrf51822 (16KB RAM), I'm trying to retain some data (RAM) after watchdog reset. when I load only the softdevice and my app, the RAM retention workings, but when I used it with bootloader, the data is always reset. I use this customized scatter file :

RW_IRAM2 0x20002000 UNINIT 0x20  {
   main.o (rtc_ram)
  }
  
  RW_IRAM1 0x20002020 0x3FE0{  ; RW data
   .ANY (+RW +ZI)
  }

I can see the data on the map file are set in the region 0x20002000 to 0x20002080, but each time the system reset, the data is reset.

I configured RAM retention on BLOCK1 after advertising start function

if(sd_power_ramon_set(0x00020003) != NRF_SUCCESS)
        {
        NVIC_SystemReset();
        }

I configured the desired RAM retention data this way

static uint8_t session_start_flag	__attribute__((section("rtc_ram"),zero_init));
static uint8_t reset_after_hang		__attribute__((section("rtc_ram"),zero_init));
static uint16_t steps_store_index	__attribute__((section("rtc_ram"),zero_init));
static uint16_t last_read_block		__attribute__((section("rtc_ram"),zero_init));
static uint16_t last_offset			  __attribute__((section("rtc_ram"),zero_init));

what could be the issue? I thought that when the app is valid, it's launched automatically on watchdog reset and the bootloader code is just flash code???, I mean the RAM is not affected by the bootlader

Parents
  • Please refer to this answer to a very similar question.

    The suggested solution for that case does not work for you, but the initial part of the answer is: the reset behavior table found in section 12.1.19 of the nRF51 RM states that RAM content may be corrupted for all reset sources but CPU lockup and softreset. This means that even if you do everything by the book with regard to RAM retention, you still risk the data being corrupted after a watchdog reset. So what you ask is not possible on the nRF51 HW, as you cannot be confident that RAM data is valid after a watchdog reset.

    Your updated question asks about differenced using bootloader or not. The bootloader is always run at startup if it is flashed, though it will not do much in the normal case where there is no upgrade ongoing. It will do some basic configuration (configure LED's, enable timer and GPIO for button etc) and check whether it is in the process of upgrading or not, and if there is a valid application. Then it will start the application. This means that you risk losing data that is stored in the RAM area for the bootloader, also when not upgrading.

    So in your case you have two separate issues that can make your data corrup:

    1. RAM content may be corrupted after watchdog reset
    2. Bootloader will use some of it's RAM at startup even if no upgrade is ongoing.
  • I have updated the answer to cover the situation where you use a bootloader.

Reply Children
No Data
Related