Browse Source

Add ESP32 Reset Reason

pull/2765/head
Marco 3 weeks ago
parent
commit
e7db7c5a94
  1. 4
      src/helpers/CommonCLI.cpp
  2. 36
      src/helpers/ESP32Board.h

4
src/helpers/CommonCLI.cpp

@ -944,13 +944,9 @@ void CommonCLI::handleGetCmd(uint32_t sender_timestamp, char* command, char* rep
strcpy(reply, "ERROR: Power management not supported"); strcpy(reply, "ERROR: Power management not supported");
#endif #endif
} else if (memcmp(config, "pwrmgt.bootreason", 17) == 0) { } else if (memcmp(config, "pwrmgt.bootreason", 17) == 0) {
#ifdef NRF52_POWER_MANAGEMENT
sprintf(reply, "> Reset: %s; Shutdown: %s", sprintf(reply, "> Reset: %s; Shutdown: %s",
_board->getResetReasonString(_board->getResetReason()), _board->getResetReasonString(_board->getResetReason()),
_board->getShutdownReasonString(_board->getShutdownReason())); _board->getShutdownReasonString(_board->getShutdownReason()));
#else
strcpy(reply, "ERROR: Power management not supported");
#endif
} else if (memcmp(config, "pwrmgt.bootmv", 13) == 0) { } else if (memcmp(config, "pwrmgt.bootmv", 13) == 0) {
#ifdef NRF52_POWER_MANAGEMENT #ifdef NRF52_POWER_MANAGEMENT
sprintf(reply, "> %u mV", _board->getBootVoltage()); sprintf(reply, "> %u mV", _board->getBootVoltage());

36
src/helpers/ESP32Board.h

@ -155,6 +155,42 @@ public:
void setInhibitSleep(bool inhibit) { void setInhibitSleep(bool inhibit) {
inhibit_sleep = inhibit; inhibit_sleep = inhibit;
} }
uint32_t getResetReason() const override {
return esp_reset_reason();
}
// https://docs.espressif.com/projects/esp-idf/en/v4.4.7/esp32/api-reference/system/system.html
const char* getResetReasonString(uint32_t reason) {
switch (reason) {
case ESP_RST_UNKNOWN:
return "Unknown or first boot";
case ESP_RST_POWERON:
return "Power-on reset";
case ESP_RST_EXT:
return "External reset";
case ESP_RST_SW:
return "Software reset";
case ESP_RST_PANIC:
return "Panic / exception reset";
case ESP_RST_INT_WDT:
return "Interrupt watchdog reset";
case ESP_RST_TASK_WDT:
return "Task watchdog reset";
case ESP_RST_WDT:
return "Other watchdog reset";
case ESP_RST_DEEPSLEEP:
return "Wake from deep sleep";
case ESP_RST_BROWNOUT:
return "Brownout (low voltage)";
case ESP_RST_SDIO:
return "SDIO reset";
default:
static char buf[40];
snprintf(buf, sizeof(buf), "Unknown reset reason (%d)", reason);
return buf;
}
}
}; };
class ESP32RTCClock : public mesh::RTCClock { class ESP32RTCClock : public mesh::RTCClock {

Loading…
Cancel
Save