Skip to content

Commit 50a7ba2

Browse files
tvedpgeorge
authored andcommitted
esp32/modmachine: Fix machine.reset_cause to use IDF's esp_reset_reason.
The code previously called rtc_get_reset_reason which is a "raw" reset cause. The ESP-IDF massages that for the proper reset cause available from esp_reset_reason. Fixes issue micropython#5134.
1 parent 1662a0b commit 50a7ba2

File tree

1 file changed

+13
-19
lines changed

1 file changed

+13
-19
lines changed

ports/esp32/modmachine.c

+13-19
Original file line numberDiff line numberDiff line change
@@ -146,36 +146,30 @@ STATIC mp_obj_t machine_deepsleep(size_t n_args, const mp_obj_t *pos_args, mp_ma
146146
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(machine_deepsleep_obj, 0, machine_deepsleep);
147147

148148
STATIC mp_obj_t machine_reset_cause(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
149-
switch (rtc_get_reset_reason(0)) {
150-
case POWERON_RESET:
149+
switch (esp_reset_reason()) {
150+
case ESP_RST_POWERON:
151+
case ESP_RST_BROWNOUT:
151152
return MP_OBJ_NEW_SMALL_INT(MP_PWRON_RESET);
152153
break;
153-
case SW_RESET:
154-
case SW_CPU_RESET:
155-
return MP_OBJ_NEW_SMALL_INT(MP_SOFT_RESET);
156-
break;
157-
case OWDT_RESET:
158-
case TG0WDT_SYS_RESET:
159-
case TG1WDT_SYS_RESET:
160-
case RTCWDT_SYS_RESET:
161-
case RTCWDT_BROWN_OUT_RESET:
162-
case RTCWDT_CPU_RESET:
163-
case RTCWDT_RTC_RESET:
164-
case TGWDT_CPU_RESET:
154+
155+
case ESP_RST_INT_WDT:
156+
case ESP_RST_TASK_WDT:
157+
case ESP_RST_WDT:
165158
return MP_OBJ_NEW_SMALL_INT(MP_WDT_RESET);
166159
break;
167160

168-
case DEEPSLEEP_RESET:
161+
case ESP_RST_DEEPSLEEP:
169162
return MP_OBJ_NEW_SMALL_INT(MP_DEEPSLEEP_RESET);
170163
break;
171164

172-
case EXT_CPU_RESET:
165+
case ESP_RST_SW:
166+
case ESP_RST_PANIC:
167+
case ESP_RST_EXT: // Comment in ESP-IDF: "For ESP32, ESP_RST_EXT is never returned"
173168
return MP_OBJ_NEW_SMALL_INT(MP_HARD_RESET);
174169
break;
175170

176-
case NO_MEAN:
177-
case SDIO_RESET:
178-
case INTRUSION_RESET:
171+
case ESP_RST_SDIO:
172+
case ESP_RST_UNKNOWN:
179173
default:
180174
return MP_OBJ_NEW_SMALL_INT(0);
181175
break;

0 commit comments

Comments
 (0)