Page 1 of 1

Preserving error information between reboots with RTC_NOINIT_ATTR

Posted: Thu Jul 23, 2020 8:02 am
by JosuGZ
Hi, I want to preserve some memory between reboots so I can check the cause (for example, by setting a variable before calling abort); or just keep some counters (like an error counter).

I've seen that I can achieve that with "RTC_NOINIT_ATTR", but I'm not sure the bootloader will not override the values, is there a proper way to do this?

Also, it would be interesting to have some kind of stack trace or core dump preserved, I'm not sure if that can be done.

Re: Preserving error information between reboots with RTC_NOINIT_ATTR

Posted: Wed Jan 13, 2021 3:42 pm
by JosuGZ
It seems like I should check the linker script for this, although I still don't know how to do it...

Re: Preserving error information between reboots with RTC_NOINIT_ATTR

Posted: Thu Jan 14, 2021 1:53 am
by ESP_Sprite
The bootloader shouldn't touch the RTC memory.

Re: Preserving error information between reboots with RTC_NOINIT_ATTR

Posted: Thu Jan 28, 2021 8:15 am
by WilliamR
This should preserve esp_log information through aborts, reboots, deep-sleep etc. Unfortunately, if the power supply is lost to the ESP32, so is this information. This information is stored through RTC RAM.

Here is a bare bones, simple proof of concept to provide a starting point for you. I have made it as minimal as possible to convey the core concept. Note that it gibberish will be printed on the first run, and the log_message (Test Message), will be printed on the second run, having been saved in RTC RAM

Code: Select all

// Global declaration
RTC_NOINIT_ATTR char recent_log[1000];
static const char* TAG = "MyModule";

// Handler to direct log output to RTC RAM
int _log_vprintf(const char *fmt, va_list args)
{
	//Should probably wrap this in a semaphore if running on multiple cores for thread safety
	sprintf(recent_log,"%s", fmt);

	return vprintf(fmt, args);
}


void app_main()
{
	esp_log_set_vprintf(_log_vprintf);
	printf("Message = [%s]\n", recent_log);
	ESP_LOGW(TAG, "Test Message");
	delay(1000);
	esp_restart();
}