mirror of
https://github.com/espressif/esp-idf.git
synced 2025-08-08 12:10:59 +00:00
esp32: add API to get reset reason
This commit is contained in:
@@ -40,7 +40,7 @@
|
||||
#include "esp_spi_flash.h"
|
||||
#include "esp_cache_err_int.h"
|
||||
#include "esp_app_trace.h"
|
||||
#include "esp_system.h"
|
||||
#include "esp_system_internal.h"
|
||||
#include "sdkconfig.h"
|
||||
#if CONFIG_SYSVIEW_ENABLE
|
||||
#include "SEGGER_RTT.h"
|
||||
@@ -121,6 +121,20 @@ void __attribute__((weak)) vApplicationStackOverflowHook( TaskHandle_t xTask, s
|
||||
abort();
|
||||
}
|
||||
|
||||
/* These two weak stubs for esp_reset_reason_{get,set}_hint are used when
|
||||
* the application does not call esp_reset_reason() function, and
|
||||
* reset_reason.c is not linked into the output file.
|
||||
*/
|
||||
void __attribute__((weak)) esp_reset_reason_set_hint(esp_reset_reason_t hint)
|
||||
{
|
||||
}
|
||||
|
||||
esp_reset_reason_t __attribute__((weak)) esp_reset_reason_get_hint(void)
|
||||
{
|
||||
return ESP_RST_UNKNOWN;
|
||||
}
|
||||
|
||||
|
||||
static bool abort_called;
|
||||
|
||||
static __attribute__((noreturn)) inline void invoke_abort()
|
||||
@@ -147,6 +161,12 @@ void abort()
|
||||
#if !CONFIG_ESP32_PANIC_SILENT_REBOOT
|
||||
ets_printf("abort() was called at PC 0x%08x on core %d\r\n", (intptr_t)__builtin_return_address(0) - 3, xPortGetCoreID());
|
||||
#endif
|
||||
/* Calling code might have set other reset reason hint (such as Task WDT),
|
||||
* don't overwrite that.
|
||||
*/
|
||||
if (esp_reset_reason_get_hint() == ESP_RST_UNKNOWN) {
|
||||
esp_reset_reason_set_hint(ESP_RST_PANIC);
|
||||
}
|
||||
invoke_abort();
|
||||
}
|
||||
|
||||
@@ -234,6 +254,10 @@ void panicHandler(XtExcFrame *frame)
|
||||
}
|
||||
#endif //!CONFIG_FREERTOS_UNICORE
|
||||
|
||||
if (frame->exccause == PANIC_RSN_INTWDT_CPU0 || frame->exccause == PANIC_RSN_INTWDT_CPU1) {
|
||||
esp_reset_reason_set_hint(ESP_RST_INT_WDT);
|
||||
}
|
||||
|
||||
haltOtherCore();
|
||||
esp_dport_access_int_abort();
|
||||
panicPutStr("Guru Meditation Error: Core ");
|
||||
@@ -333,6 +357,7 @@ void xt_unhandled_exception(XtExcFrame *frame)
|
||||
return;
|
||||
}
|
||||
panicPutStr(". Exception was unhandled.\r\n");
|
||||
esp_reset_reason_set_hint(ESP_RST_PANIC);
|
||||
}
|
||||
commonErrorHandler(frame);
|
||||
}
|
||||
|
Reference in New Issue
Block a user