Save array of bytes in the RTC Fast Memory

andreaz98
Posts: 4
Joined: Wed Mar 30, 2022 1:42 pm

Save array of bytes in the RTC Fast Memory

Postby andreaz98 » Fri Jun 03, 2022 8:20 am

Hello

I'm developing an application that must save some buffers in the RTC Fast Memory in order to persist data between deep sleeps.

My code is something like

Code: Select all

RTC_DATA_ATTR static uint8_t * buffer;
RTC_DATA_ATTR static int flag = 0;

void app_main(void)
{ 
	/*compute the dimension of the buffer if and only if this cycle is not a wake up from deep sleep*/
	if(flag == 0){
		buffer = (uint8_t *)malloc(computed_dimension);
	}
	else {
		/*read the content of the buffer for the application logic*/
		/*main application logic*/
	}
	
	/*reads and writes on the buffer*/
	
	esp_sleep_pd_config(ESP_PD_DOMAIN_RTC_PERIPH, ESP_PD_OPTION_OFF);
        esp_sleep_pd_config(ESP_PD_DOMAIN_VDDSDIO, ESP_PD_OPTION_OFF);
        
        esp_sleep_enable_timer_wakeup(TIME_TO_SLEEP * uS_TO_S_FACTOR);
        
        flag = 1;
        
        esp_deep_sleep_start();
}
I expected that the above code worked but I get a LoadStoreError when the code tries to access the buffer, that means the content of buffer remains in the RAM losing its meaning after the deep sleep. How can I tell the ESP32 to save the content from the RAM pointed by buffer to the RTC Fast RAM?

Details of the working environment:
Ubuntu 20.04.4 LTS
Platformio 6.0.2
Framework ESP-IDF 4.3.2
Board az-delivery-devkit-v4 ESP32

ESP_Sprite
Posts: 9730
Joined: Thu Nov 26, 2015 4:08 am

Re: Save array of bytes in the RTC Fast Memory

Postby ESP_Sprite » Fri Jun 03, 2022 9:51 am

In your code, only the pointer to 'buffer' is in RTC memory, not the buffer data itself. I don't think the heap allocator is capable of allocating persistent RTC memory, so you'd have to statically allocate memory; e.g.

Code: Select all

RTC_DATA_ATTR static uint8_t buffer[128];

andreaz98
Posts: 4
Joined: Wed Mar 30, 2022 1:42 pm

Re: Save array of bytes in the RTC Fast Memory

Postby andreaz98 » Fri Jun 03, 2022 10:53 am

Ok, I understand. I must set a static size.

Thank you for the clear answer ESP_Sprite

Who is online

Users browsing this forum: Baidu [Spider], Bing [Bot] and 76 guests