You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
So in the recent days i tried to figure out how would one be able to log the crash log trace or the ESP's reset reason.
This would be really handy because in my case, my esp using it's serial for modbus RTU and no other PINS are available for monitoring the serial output of the crash logs, and in random times it crashes. Sometimes it goes one and a half day without problem, but sometimes it crashing about 5 mins after bootup.
On esp8266 core it is possible to write the crash reason to a file with custom log callback function, and there is a thing called reset reason on esp8266 with detailed information return when the esp boots.
In the esp32 arduino core i found no working solution to log the crash detailed reason to my file system. I tried two different approaches.
One is to register my own callback function to the LOGE functions wich ( i think ) calls when some crash occours.
That one didn't go well.
What i tried with it is this:
static char log_print_buffer[512];
static char APP_NAME[] = "My_Home";
static char Crash_File_Path[] = "/Crash_LOGS.txt";
int redirectToF_System(const char *szFormat, va_list args) {
int ret = vsnprintf(log_print_buffer, sizeof(log_print_buffer), szFormat, args);
if (ret >= 0){
File g;
if(LITTLEFS.exists(Crash_File_Path)){
g = LITTLEFS.open(Crash_File_Path, "a");
}else{
g = LITTLEFS.open(Crash_File_Path, "w");
}
if (!g) {}else{
g.write((uint8_t *)log_print_buffer, (size_t)ret);
}
g.close();
}
return ret;
}
static const inline void Crash_Log_Init(){
esp_log_set_vprintf(redirectToF_System);
ESP_LOGE(APP_NAME, "Writing via ESP_LOGI!\n");
esp_log_write(ESP_LOG_ERROR, APP_NAME, "I can write like this all day.\n");
}
void setup(){
Crash_Log_Init();
}
void loop(){}
I found this test sketch on some github issue. The esp_log_write(ESP_LOG_ERROR, APP_NAME, "I can write like this all day.\n"); is successfully writes to the Crash_LOGS.txt file on LITTLEFS. But no other log function is calling my custom function other than that.
The next approach i tried is getting the reset reason on bootup. This indeed give me some clue about the crashes but nothing too obvious to be able to follow trought the problem.
void Save_Reset_Reason(RESET_REASON reason,int core){
String Reason = "\n********************\nReset Reason on core: ";
Reason += core;
Reason += "\n";
switch (reason){
case 1 : Reason += "Vbat power on reset";break;
case 3 : Reason += "Software reset digital core";break;
case 4 : Reason += "Legacy watch dog reset digital core";break;
case 5 : Reason += "Deep Sleep reset digital core";break;
case 6 : Reason += "Reset by SLC module, reset digital core";break;
case 7 : Reason += "Timer Group0 Watch dog reset digital core";break;
case 8 : Reason += "Timer Group1 Watch dog reset digital core";break;
case 9 : Reason += "RTC Watch dog Reset digital core";break;
case 10 : Reason += "Instrusion tested to reset CPU";break;
case 11 : Reason += "Time Group reset CPU";break;
case 12 : Reason += "Software reset CPU";break;
case 13 : Reason += "RTC Watch dog Reset CPU";break;
case 14 : Reason += "for APP CPU, reseted by PRO CPU";break;
case 15 : Reason += "Reset when the vdd voltage is not stable";break;
case 16 : Reason += "RTC Watch dog reset digital core and rtc module";break;
default : Reason += "NO_MEAN";
}
Reason += "\n********************";
File f = LITTLEFS.open("/ResetReason.txt", "a");
if (!f) {
String Error = "Can't open ResetReason for append.";
Error_iras(Error);
}else {
f.print(Reason);
}
f.close();
}
void setup(){
Save_Reset_Reason(rtc_get_reset_reason(0),0);
Save_Reset_Reason(rtc_get_reset_reason(1),1);
}
void loop(){}
My ResetReason.txt file looks like this now:
********************
Reset Reason on core: 0
Software reset CPU
****************************************
Reset Reason on core: 1
Software reset CPU
********************
********************
Reset Reason on core: 0
RTC Watch dog reset digital core and rtc module
****************************************
Reset Reason on core: 1
for APP CPU, reseted by PRO CPU
********************
********************
Reset Reason on core: 0
RTC Watch dog reset digital core and rtc module
****************************************
Reset Reason on core: 1
for APP CPU, reseted by PRO CPU
********************
********************
Reset Reason on core: 0
Software reset CPU
********************
********************
Reset Reason on core: 1
Software reset CPU
********************
********************
Reset Reason on core: 0
Software reset CPU
********************
********************
Reset Reason on core: 1
Software reset CPU
********************
********************
Reset Reason on core: 0
Software reset CPU
********************
********************
Reset Reason on core: 1
Software reset CPU
********************
********************
Reset Reason on core: 0
Software reset CPU
********************
********************
Reset Reason on core: 1
Software reset CPU
********************
********************
Reset Reason on core: 0
Software reset CPU
********************
********************
Reset Reason on core: 1
Software reset CPU
********************
********************
Reset Reason on core: 0
Software reset CPU
********************
********************
Reset Reason on core: 1
Software reset CPU
********************
********************
Reset Reason on core: 0
Software reset CPU
********************
********************
Reset Reason on core: 1
Software reset CPU
********************
********************
Reset Reason on core: 0
Software reset CPU
********************
********************
Reset Reason on core: 1
Software reset CPU
********************
********************
Reset Reason on core: 0
Software reset CPU
********************
********************
Reset Reason on core: 1
Software reset CPU
********************
********************
Reset Reason on core: 0
Software reset CPU
********************
********************
Reset Reason on core: 1
Software reset CPU
********************
********************
Reset Reason on core: 0
RTC Watch dog reset digital core and rtc module
********************
********************
Reset Reason on core: 1
for APP CPU, reseted by PRO CPU
********************
********************
Reset Reason on core: 0
Software reset CPU
********************
********************
Reset Reason on core: 1
Software reset CPU
********************
********************
Reset Reason on core: 0
Software reset CPU
********************
********************
Reset Reason on core: 1
Software reset CPU
********************
********************
Reset Reason on core: 0
Software reset CPU
********************
********************
Reset Reason on core: 1
Software reset CPU
********************
********************
Reset Reason on core: 0
Software reset CPU
********************
********************
Reset Reason on core: 1
Software reset CPU
********************
There was really some Software reset on the CPU by me, like OTA upload and things like that wich i know about, but most of them the crashes.
How can a CRASH software reset the CPU?
Does anyone know about a good working solution to save the crash dump to the FILESYSTEM before reset?
The text was updated successfully, but these errors were encountered:
[STALE_SET] This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 14 days if no further activity occurs. Thank you for your contributions.
So in the recent days i tried to figure out how would one be able to log the crash log trace or the ESP's reset reason.
This would be really handy because in my case, my esp using it's serial for modbus RTU and no other PINS are available for monitoring the serial output of the crash logs, and in random times it crashes. Sometimes it goes one and a half day without problem, but sometimes it crashing about 5 mins after bootup.
On esp8266 core it is possible to write the crash reason to a file with custom log callback function, and there is a thing called reset reason on esp8266 with detailed information return when the esp boots.
In the esp32 arduino core i found no working solution to log the crash detailed reason to my file system. I tried two different approaches.
One is to register my own callback function to the LOGE functions wich ( i think ) calls when some crash occours.
That one didn't go well.
What i tried with it is this:
I found this test sketch on some github issue. The
esp_log_write(ESP_LOG_ERROR, APP_NAME, "I can write like this all day.\n");
is successfully writes to the Crash_LOGS.txt file on LITTLEFS. But no other log function is calling my custom function other than that.The next approach i tried is getting the reset reason on bootup. This indeed give me some clue about the crashes but nothing too obvious to be able to follow trought the problem.
My ResetReason.txt file looks like this now:
There was really some Software reset on the CPU by me, like OTA upload and things like that wich i know about, but most of them the crashes.
How can a CRASH software reset the CPU?
Does anyone know about a good working solution to save the crash dump to the FILESYSTEM before reset?
The text was updated successfully, but these errors were encountered: