-->
Page 1 of 1

RTC Memory

PostPosted: Wed Nov 29, 2017 4:01 am
by ekalyvio
Hello. I have the following function:
Code: Select allstatic uint8_t mem[512];

void RTCMemoryTest1() {
   sdk_system_rtc_mem_read(0x00, &mem[0], 512);
   for (int i=0; i<= 511; ++i) {
      printf("MEM %d: %d\n", i, mem[i]);
      mem[i] = i;
   }
   sdk_system_rtc_mem_write(0x00, &mem[0], 512);

   sdk_system_deep_sleep(1000000);
   vTaskDelay(100000);
}

This function I call it inside my main.
After a reset of the system, I see that it can preserve the data in the RTC memory but not all of them.
The first 32 bytes (address 0 to 31) are not preserved. Also, bytes from 248 to 251 and bytes from 256 to 264 are not preserved too.

Can someone verify my findings?
Also is somewhere on internet any Espressif document that states something like that? I can not find something myself.

Thank you very much.

Re: RTC Memory

PostPosted: Sun Oct 14, 2018 9:07 pm
by davydnorris
So you have a problem with a couple of things here, but I too have found an issue with the RTC memory not working as expected that may be related.

Firstly, the RTC memory is 32bit aligned so the function doesn't take a length in bytes, everything is in 32bit slots or words.
Secondly, the first 256bytes (64 slots) is reserved for the system - the RTC user memory is still 512bytes (128 slots) in size but it starts at slot 64, so your function should be:

Code: Select allstatic uint8_t mem[512];

void RTCMemoryTest1() {
   sdk_system_rtc_mem_read(64, &mem[0], 128);
   for (int i=0; i<= 511; ++i) {
      printf("MEM %d: %d\n", i, mem[i]);
      mem[i] = i;
   }
   sdk_system_rtc_mem_write(64, &mem[0], 128);

   sdk_system_deep_sleep(1000000);
   vTaskDelay(100000);
}


So this would explain what you saw for bytes 0-255, but not bytes 256 to 264.

I am also seeing memory problems, but higher up. I'm still trying to work out exactly what's going on but the user area doesn't seem to be one contiguous block

Re: RTC Memory

PostPosted: Mon Oct 15, 2018 2:07 am
by schufti
hmm,
the 2c-esp8266_non_os_sdk_api_reference_en.pdf
§3.3.23/24 has all the details on size and access,
and
§3.3.21 gives all details about data retention on reset/power/chpd etc.

so definitely not hard to find if willing to read some documentation ....

and https://github.com/esp8266/Arduino/issues/619 has some details about anomalies

Re: RTC Memory

PostPosted: Thu Oct 18, 2018 10:58 pm
by davydnorris
Been digging more and I was wrong on half my response above, and this seems to have sorted out my problem (maybe lol).

The units in the function calls are inconsistent - the first parameter is in 32 byte 'slots', but the third parameter is in bytes, not 32 bit slots as I mentioned. The first 256 bytes (64 slots) is still system reserved, so the user memory starts at slot 64. So your function should be:

Code: Select allstatic uint8_t mem[512];

void RTCMemoryTest1() {
   sdk_system_rtc_mem_read(64, mem, 512);
   for (int i=0; i<= 511; ++i) {
      printf("MEM %d: %d\n", i, mem[i]);
      mem[i] = i;
   }
   sdk_system_rtc_mem_write(64, mem, 512);

   sdk_system_deep_sleep(1000000);
   vTaskDelay(100000);
}


When I run the NonOS version of this code, I now get correct data upon wake.