You can chat about native SDK questions and issues here.

User avatar
By davydnorris
#78626 Hi all,

I am trying to use the user area of the RTC memory to store values and I am finding that certain areas are getting corrupted, or are not writable.

I am using NonOS SDK 2.2.1 and have written a small program to write random sized chunks of data to the RTC user memory area, then read them back. I use a data structure like this:

Code: Select all#define RTC_SIZE (512 - 2*sizeof(uint32_t))

struct {
    uint32_t crc;
    uint32_t len;
    uint8_t data[RTC_SIZE];
} rtcData;

//fill with random length of random data
//store length of data in rtcData.len
//calculate CRC32 by crc32((uint8_t*)&rtcData.len, sizeof(rtcData)-4)
//store crc in rcData.crc

then I write the data with:
Code: Select allsystem_rtc_mem_write(64, (void *)&rtc_mem, sizeof(rtcData)/4);

and then read it back with:
Code: Select allsystem_rtc_mem_read(64, (void *)&rtc_mem, sizeof(rtcData)/4);

When I checked the checksum, it didn't match. I then printed out the data before and after and I found that most of the data matched but that there were several locations where the values were different. This seemed to be the case each time I tried writing random amounts of data, and it seems like the regions are scattered through the user area of the RTC memory, which makes it very difficult to write larger blocks of information.

My next test is to read and write a 32 bit value at a time to try and map out the problem slots, but this is happening on several different ESP8266 modules (Lolin v3, Wemos, AI Thinker ESP-12F - I haven't tried on WROOM-02 yet)

Do you know of any SDK functions that are using the RTC user memory area, or any reason why the RTC memory would be corrupted?

BTW, this is literally writing and then reading immediately after - not even going through a deep sleep. If I read after a deep sleep then the data is the same 'bad' data that I saw immediately after writing (most slots OK but not all of them)