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

RAM retention settings with SoftDevice enabled

Hello,

 

I am using nRF52832, SDK_15.3.0, S132 SoftDevice and Segger for flashing the image. I am using ‘ble_app_blinky’.

I have few variables in application. These will be keep on changing based on different conditions in application. Other than power reset, those variables to be retained both in System ON and System OFF mode.

 

1) I searched entire ble_app_blinky project but I could not find sd_power_ram_power_set(). Still RAM content retained, when device wakes from “System ON” mode.

a) Whether SoftDevice will enable these settings, so that variables are retained even in System ON mode.

b) (Or) Since by default after reset, both bits A & B are set to 1 indicating RAM section S0 & S1 are enabled by default in System OF mode.

2) Device went to System OFF mode. But content in variables are lost. As per below links

a) I want to retain entire RAM rather than ".retained_section" for different variables.

b) If entire RAM is not retained during System OFF, then what is the purpose of S0RETENTION and S1RETENTION in RAM[0].POWER register.

c) Whether blow code is good enough so that entire RAM will retained even in System OFF mode.  But still I am not able to see the retained value.

https://devzone.nordicsemi.com/f/nordic-q-a/47620/ram-retention-of-softdevice-ram-region

https://devzone.nordicsemi.com/f/nordic-q-a/36099/ram-retention-problem

    uint8_t i;
    for(i = 0; i < 8; i++) // Retain RAM 0 - RAM 7
    {
        sd_power_ram_power_set(i, (POWER_RAM_POWER_S0POWER_On << POWER_RAM_POWER_S0POWER_Pos) |
                                  (POWER_RAM_POWER_S1POWER_On << POWER_RAM_POWER_S1POWER_Pos) |
                                  (POWER_RAM_POWER_S0RETENTION_On << POWER_RAM_POWER_S0RETENTION_Pos) |
                                  (POWER_RAM_POWER_S1RETENTION_On << POWER_RAM_POWER_S1RETENTION_Pos));
    }
    
    u8SystemOFFTestCounter++;
    // Start execution.
    NRF_LOG_INFO("SystemOFF Test %d", u8SystemOFFTestCounter);

3) Even I thought to skip GPIO initialization. Since variables are not retained in RAM, I am getting code crash.

    /* Reset reason */
    uint32_t rr = log_resetreason();
    
    // During System OFF mode, no need to re-initialize GPIO pins (This will avoid Glitch on pins)
    if(rr == NRF_POWER_RESETREAS_OFF_MASK)
    {
        leds_init();
        buttons_init();
    }

Also I have gone through "ram_retention" which is without softDevice and "ble_app_pwr_profiling" example where sd_power_ram_power_set() is no where called. I am bit confused.

I have gone through lot of mails on forum. But there is not straight froward answer.

Do we need to change any Segger settings to avoid RAM initialization while wake-up from System OFF. Please take this issue on high priority.

Thanks & Regards

Vishnu Beema

  • Hi Vishnu

    1. RAM retention in system ON mode is enabled by default, that is correct. Most applications use system ON idle mode continuously, and having at least partial RAM retention is critical. 

    2. a. Most examples come with a .non_init section that can be used to declare retained variables, without having to make any changes to the flash_placement.xml file. 

    To do this just declare the variables like this:

    static uint32_t my_variable __attribute__((section(".non_init")));

    b. Technically the RAM is still retained, but it gets zero initialized during the reset sequence. I agree it doesn't make sense to enable RAM retention if you don't put the memory in the .non_init section. 

    c. That code should suffice, yes. Can you try using the .non_init section like I suggested earlier and see if it works?

    3. What part of the code causes the crash? 

    Do you get an assert from the SoftDevice, or an error code in return from one of the SDK modules?

    Best regards
    Torbjørn

  • Thank you for your confirmation.

    1) So without non_init section, there is no RAM retention even by calling sd_power_ram_power_set().

    2) My worry is, I don't know which are all required to be kept in RAM. As mentioned above when I skip leds_init() and buttons_init() I am getting ASSERT. Below is once such example when I call app_button_enable() or app_button_disable().

    ASSERT(mp_buttons);

    Thanks & Regards

    Vishnu Beema

  • Hi Vishnu

    1) RAM retention refers to the ability of the RAM to retain it's state during power down, which is indeed working. When you leave system OFF mode the RAM content is still intact. 

    What happens here is that the RAM is overwritten after you wake from system OFF and go through the MCU startup procedure, which the RAM retention doesn't protect you from. 

    2) This is probably caused by the internal variables of the led and button modules not being retained. 

    The normal procedure is to re-initialize the various SDK modules after wakeup from system OFF. 

    Is this not a viable option in your application?

    Otherwise you would have to ensure that all the global and static variables in these modules are located in a .non_init section. 

    Best regards
    Torbjørn

  • Hi,

    I only concerned with one scenario where I set LED ON based on some conditions and then go to System OFF mode. After coming out of System off mode and if initialization routine executes LED will be switched OFF. I want to avoid this.

    Thanks & Regards

    Vishnu Beema

  • Hi Vishnu

    To avoid this I think the easiest way is to make a copy of the bsp_board_leds_init() function somewhere (in main.c for instance), and run that rather than running bsp_board_init(BSP_INIT_LEDS). 

    Then you can comment out the last line of the bsp_board_leds_init function, where the LED's are turned off:

    static void bsp_board_leds_init_copy(void)
    {
    #if defined(BOARD_PCA10059)
      // If nRF52 USB Dongle is powered from USB (high voltage mode),
      // GPIO output voltage is set to 1.8 V by default, which is not
      // enough to turn on green and blue LEDs. Therefore, GPIO voltage
      // needs to be increased to 3.0 V by configuring the UICR register.
      if (NRF_POWER->MAINREGSTATUS &
      (POWER_MAINREGSTATUS_MAINREGSTATUS_High <<   POWER_MAINREGSTATUS_MAINREGSTATUS_Pos))
      {
        gpio_output_voltage_setup();
      }
    #endif

      uint32_t i;
      for (i = 0; i < LEDS_NUMBER; ++i)
      {
        nrf_gpio_cfg_output(m_board_led_list[i]);
      }
      // bsp_board_leds_off(); - This line should be commented out
    }

    This code can be found on line 125 of boards.c

    Best regards
    Torbjørn

Related