Beware that this post is related to an SDK in maintenance mode
More Info: Consider nRF Connect SDK for new designs
This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

RAM retention between system resets (#pragma NOINIT replacement)

Hi,

My application is based of ble_freertos_hrs example (SDK 14.2, nRF52832) and I need some variables to survive an assertion.

It appears that Keil has deprecated #pragma NO_INIT that did just that.

I've noticed a post dealing with same issues here, but unfortunately, I find it very hard to follow as I'm not very familiar with Linker configuration files etc.

Is there a simple step-by-step guideline as how to make it work?

Thanks

Parents
  • Hi,

    We used to allocate a no init section in our legacy bootloader for sharing data between application and bootloader (pre-SDK12). You can copy this approach to your example, it doesn't require you to edit any linker/scatter files. 

    Steps:

    1. Define the variable you want to keep retained with  __attribute__((section("NoInit"), zero_init)); .e.g, static uint32_t dummy __attribute__((section("NoInit"), zero_init)); 

    2. Open option for target options allocate a new memory segment and tick the "NoInit" checkbox.

    3. Right click on the source file you defined the variable in and select "options for File..". Then select the new ram section you created from the dropdown menu for Zero initialized data.

    4. Dummy variable should now be linked to the IRAM2 section.

  • Dear Vidar

    THANK YOU.

    Your answer saved me hours of googling (on top of the hours already spent)

    Further question:

    What would be the way to 'uninit' specific variables rather than all variables within a file?

    Again, many many thanks for your prompt response

Reply Children
  • I forgot that the source files setting applied to all .bss variables in that file. I'm not sure if it is possible to set noninit on one specific variable without touching the scatter file. 

    Alternative proposals:

    1. (Probably easiest) Store the data to an unallocated part of RAM memory like we do in the ram retention example.

    2. Use the Keil scatter file (linker script): Open options for target and click on the Linker tab. Then untick the checkbox for "Use Memory Layout from target Dialog and modify the scatter file so it looks something like this:

Related