diff --git a/cores/esp8266/Esp.cpp b/cores/esp8266/Esp.cpp index 2a9035519..627fdcf2c 100644 --- a/cores/esp8266/Esp.cpp +++ b/cores/esp8266/Esp.cpp @@ -22,6 +22,8 @@ extern "C" { #include "user_interface.h" + +extern struct rst_info resetInfo; } //extern "C" void ets_wdt_init(uint32_t val); @@ -279,3 +281,16 @@ uint32_t EspClass::getFlashChipSizeByChipId(void) { return 0; } } + +String EspClass::getResetInfo(void) { + if(resetInfo.reason != 0) { + char buff[150]; + sprintf(&buff[0], "Fatal exception:%d flag:%d epc1:0x%08x epc2:0x%08x epc3:0x%08x excvaddr:0x%08x depc:0x%08x", resetInfo.exccause, resetInfo.reason, resetInfo.epc1, resetInfo.epc2, resetInfo.epc3, resetInfo.excvaddr, resetInfo.depc); + return String(buff); + } + return String("flag: 0"); +} + +struct rst_info * EspClass::getResetInfoPtr(void) { + return &resetInfo; +} diff --git a/cores/esp8266/Esp.h b/cores/esp8266/Esp.h index 5e356459e..ccefa0c5f 100644 --- a/cores/esp8266/Esp.h +++ b/cores/esp8266/Esp.h @@ -98,6 +98,9 @@ class EspClass { FlashMode_t getFlashChipMode(void); uint32_t getFlashChipSizeByChipId(void); + String getResetInfo(void); + struct rst_info * getResetInfoPtr(void); + inline uint32_t getCycleCount(void); }; diff --git a/cores/esp8266/core_esp8266_main.cpp b/cores/esp8266/core_esp8266_main.cpp index 34e436c88..16902b15c 100644 --- a/cores/esp8266/core_esp8266_main.cpp +++ b/cores/esp8266/core_esp8266_main.cpp @@ -34,6 +34,8 @@ extern "C" { #define LOOP_TASK_PRIORITY 0 #define LOOP_QUEUE_SIZE 1 +struct rst_info resetInfo; + int atexit(void (*func)()) { return 0; } @@ -124,6 +126,15 @@ void user_rf_pre_init() { extern "C" { void user_init(void) { + uart_div_modify(0, UART_CLK_FREQ / (74480)); + + system_rtc_mem_read(0, &resetInfo, sizeof(struct rst_info)); + if(resetInfo.reason == WDT_RST_FLAG || resetInfo.reason == EXCEPTION_RST_FLAG) { + os_printf("Last Reset:\n - flag=%d\n - Fatal exception (%d):\n - epc1=0x%08x,epc2=0x%08x,epc3=0x%08x,excvaddr=0x%08x,depc=0x%08x\n", resetInfo.reason, resetInfo.exccause, resetInfo.epc1, resetInfo.epc2, resetInfo.epc3, resetInfo.excvaddr, resetInfo.depc); + } + struct rst_info info = { 0 }; + system_rtc_mem_write(0, &info, sizeof(struct rst_info)); + uart_div_modify(0, UART_CLK_FREQ / (115200)); init(); diff --git a/tools/sdk/include/user_interface.h b/tools/sdk/include/user_interface.h index 7f593e0eb..7c4706dc4 100644 --- a/tools/sdk/include/user_interface.h +++ b/tools/sdk/include/user_interface.h @@ -30,7 +30,7 @@ enum rst_reason { DEEP_SLEEP_AWAKE_FLAG = 4 }; -struct rst_info{ +struct rst_info { uint32 reason; uint32 exccause; uint32 epc1;