Page 1 of 1

Problems reading and writing RTC memory

Posted: Mon Oct 15, 2018 8:28 am
by davydnorris
Hi Espressif,

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 all

system_rtc_mem_write(64, (void *)&rtc_mem, sizeof(rtcData)/4);

and then read it back with:

Code: Select all

system_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?

Re: Problems reading and writing RTC memory

Posted: Wed Oct 24, 2018 2:30 pm
by Her Mary

Re: Problems reading and writing RTC memory

Posted: Sun Oct 28, 2018 9:17 am
by davydnorris
I think I have resolved my problem.

The units used in the function calls are not consistent - the first parameter,

Code: Select all

uint32 des_addr
is in 32 bit blocks, but the third parameter

Code: Select all

uint32 save_size
is in bytes.

I had been assuming both parameters were in 32 bit blocks and so I was writing only 1/4 of the data