How to keep a variable while sleeping

Hi,

I would like to keep a variable while sleeping to store time. the device wakes up every minute with RTC wake up source then refreshing timestamp which is not disappear when sleeping. The device is waking up every minute but i cannot keep the variable.

Thanks in advance,

@arif.ozcan

You can use RSL10 sleep_ram_retention for reference and can do keep “variable” in sleep mode.
For example, you can put your variable in DRAM0 and keep DRAM0 retention in sleep mode.

/* Select RTC alarm time interval (in second)*/
#define RTC_ALARM_INTV_S                60.0
/* RAM instance(s) to be retained in sleep mode
 * 2 cases:
 *   - CASE 1: without memory retention (RAM_RETENTION_NUM = 0)
 *   - CASE 2: with memory retention    (RAM_RETENTION_NUM = 1, 2, ...)
 */

#define RAM_RETENTION_NUM               1

Thank you for using our community forum!

Thanks for the quick reply @martin.bela
Actually, i was trying to find out how can put the variable to retained ram section. I found a solution from somewhere.

Add to linker script in sections

   .noinit (NOLOAD) :
	{
		*(.noinit*)
    } > RAM

In source code:
static uint8_t varName __attribute__ ((section(".noinit")));

However, i cannot keep the variable in the section i want like DRAM1, DRAM2. Therefore, i have to retained all DRAM sections. Maybe, you can help me for it.

Hi @arif.ozcan,
Before running the code, you could verify if your setting is correct.
After building project, you can check map file and see if your varName is in DARM area which is retention enable for sleep.

1 Like