Allocated memory in RTC

Dav_FR
Posts: 14
Joined: Mon Mar 27, 2017 8:14 am

Allocated memory in RTC

Postby Dav_FR » Mon Mar 27, 2017 8:37 am

After read some post and documentation I think the response is no, but a sentence in the documentation let me an open doubt, so I have to ask.

It's possible allocate memory which will remain unchanged after deep sleep state?

At http://esp-idf.readthedocs.io/en/latest ... -stub.html is specified that strings must be declared array and RTC_RODATA_ATTR, but later, a sentence about the use of "rtc_wake_stub" as file prefix makes me doubt: "The second way is a better option if you need to use strings, or write other more complex code"

I checked with this small example to confirm the behaviour, but now I'm not sure if this is due to a bug when using "rtc_wake_stub" file prefix.

Code: Select all

char * test1 = NULL;
int wake_count = 0;

void RTC_IRAM_ATTR esp_wake_deep_sleep(void) {
    esp_default_wake_deep_sleep();
    wake_count++;
}

void app_main(void)
{

	if (wake_count==0) {

		test1 = (char *) pvPortMallocCaps(32, MALLOC_CAP_8BIT);
		memset(test1,0,32);
		memcpy(test1,"esp32",5);


		ESP_LOGI(tagg,"First time! %d - %s",wake_count,test1);
	} else {
		ESP_LOGI(tagg,"Not First time! %d",wake_count);
		ESP_LOGI(tagg,"String val: %s",test1);
	}

	ESP_LOGI(tagg,"Going to sleep");
	esp_deep_sleep(5*1000000);
}
Btw, there is other option which I missed?

Best regards and sorry for the incovenience,
Dav

ESP_igrr
Posts: 2072
Joined: Tue Dec 01, 2015 8:37 am

Re: Allocated memory in RTC

Postby ESP_igrr » Mon Mar 27, 2017 9:10 am

It is not possible to do dynamic allocation in RTC memory, but you can do static (compile-time) allocation.

If you define a global variable with RTC_DATA_ATTR attribute, the variable will be placed into RTC_SLOW_MEM memory. You can see how this is done in sntp example:

https://github.com/espressif/esp-idf/bl ... main.c#L49

Dav_FR
Posts: 14
Joined: Mon Mar 27, 2017 8:14 am

Re: Allocated memory in RTC

Postby Dav_FR » Mon Mar 27, 2017 9:22 am

Hi Igrr,

Thanks your for the fast response, my idea is avoid the loss of complex structures (which contains allocated pointers, lists of allocated structs, ...) between deep sleeps.

So, I guess there are two solutions for me:
- Create a fixed structure declared as RTC_DATA_ATTR and "copy" the dynamic memory to this structure before deep sleep to recover this into dynamic memory after wake up.
- Use non volatile memory, which is my last option.

I guess RTC_DATA_ATTR is applied to structs without problems.

Thanks you again,
Dav

ESP_igrr
Posts: 2072
Joined: Tue Dec 01, 2015 8:37 am

Re: Allocated memory in RTC

Postby ESP_igrr » Mon Mar 27, 2017 2:26 pm

Yes, you should be able to use RTC_DATA_ATTR with struct instances.

User avatar
martinayotte
Posts: 141
Joined: Fri Nov 13, 2015 4:27 pm

Re: Allocated memory in RTC

Postby martinayotte » Mon Mar 27, 2017 5:06 pm

which contains allocated pointers
Be aware that your structure can't hold pointers, but you need to have those arrays directly into the structures.

Dav_FR
Posts: 14
Joined: Mon Mar 27, 2017 8:14 am

Re: Allocated memory in RTC

Postby Dav_FR » Tue Mar 28, 2017 10:31 am

Sure, the problem I'm facing now is the lack of space in the RTC memory :(

Who is online

Users browsing this forum: Baidu [Spider], esperiment and 70 guests