From d0a806d7975ecc2c653d23ee48e463f38b4f1194 Mon Sep 17 00:00:00 2001 From: Scott Shawcroft Date: Tue, 8 Dec 2020 11:03:24 -0800 Subject: [PATCH] Enter safe mode after panic or brownout Uses the IDF's reset reason. Does nothing before reset. Fixes #3389 --- ports/esp32s2/supervisor/port.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/ports/esp32s2/supervisor/port.c b/ports/esp32s2/supervisor/port.c index 6222cd29041b..5a50bda698be 100644 --- a/ports/esp32s2/supervisor/port.c +++ b/ports/esp32s2/supervisor/port.c @@ -102,6 +102,14 @@ safe_mode_t port_init(void) { return NO_HEAP; } + esp_reset_reason_t reason = esp_reset_reason(); + if (reason == ESP_RST_BROWNOUT) { + return BROWNOUT; + } + if (reason == ESP_RST_PANIC) { + return HARD_CRASH; + } + return NO_SAFE_MODE; }