diff options
| author | Thorsten von Eicken | 2020-06-03 22:42:37 -0700 |
|---|---|---|
| committer | Damien George | 2021-02-19 15:15:11 +1100 |
| commit | d28dbcd6c783bc45bc4661abbb53d2b6c5397102 (patch) | |
| tree | 1a598bf93ac254b226dfee2fa29ed205de2edf2c /ports | |
| parent | c10d431819f9f7095c3573c98f01c98526a2cb0b (diff) | |
esp32: Make machine.soft_reset() work in main.py and reset_cause().
This commit fixes two issues on the esp32:
- it enables machine.soft_reset() to be called in main.py;
- it enables machine.reset_cause() to correctly identify a soft reset.
The former is useful in that it enables soft resets in applications that
are started at boot time. The support is patterned after the stm32 port.
Diffstat (limited to 'ports')
| -rw-r--r-- | ports/esp32/main.c | 9 | ||||
| -rw-r--r-- | ports/esp32/modmachine.c | 14 | ||||
| -rw-r--r-- | ports/esp32/modmachine.h | 2 |
3 files changed, 24 insertions, 1 deletions
diff --git a/ports/esp32/main.c b/ports/esp32/main.c index 001f2beae..7413798d0 100644 --- a/ports/esp32/main.c +++ b/ports/esp32/main.c @@ -73,6 +73,7 @@ void mp_task(void *pvParameter) { mp_thread_init(pxTaskGetStackStart(NULL), MP_TASK_STACK_SIZE / sizeof(uintptr_t)); #endif uart_init(); + machine_init(); // TODO: CONFIG_SPIRAM_SUPPORT is for 3.3 compatibility, remove after move to 4.0. #if CONFIG_ESP32_SPIRAM_SUPPORT || CONFIG_SPIRAM_SUPPORT @@ -118,7 +119,10 @@ soft_reset: pyexec_frozen_module("_boot.py"); pyexec_file_if_exists("boot.py"); if (pyexec_mode_kind == PYEXEC_MODE_FRIENDLY_REPL) { - pyexec_file_if_exists("main.py"); + int ret = pyexec_file_if_exists("main.py"); + if (ret & PYEXEC_FORCED_EXIT) { + goto soft_reset_exit; + } } for (;;) { @@ -135,6 +139,8 @@ soft_reset: } } +soft_reset_exit: + #if MICROPY_BLUETOOTH_NIMBLE mp_bluetooth_deinit(); #endif @@ -151,6 +157,7 @@ soft_reset: // deinitialise peripherals machine_pins_deinit(); + machine_deinit(); usocket_events_deinit(); mp_deinit(); diff --git a/ports/esp32/modmachine.c b/ports/esp32/modmachine.c index bb346ea1c..3925bcb64 100644 --- a/ports/esp32/modmachine.c +++ b/ports/esp32/modmachine.c @@ -59,6 +59,8 @@ typedef enum { MP_SOFT_RESET } reset_reason_t; +STATIC bool is_soft_reset = 0; + STATIC mp_obj_t machine_freq(size_t n_args, const mp_obj_t *args) { if (n_args == 0) { // get @@ -140,6 +142,9 @@ STATIC mp_obj_t machine_deepsleep(size_t n_args, const mp_obj_t *pos_args, mp_ma STATIC MP_DEFINE_CONST_FUN_OBJ_KW(machine_deepsleep_obj, 0, machine_deepsleep); STATIC mp_obj_t machine_reset_cause(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { + if (is_soft_reset) { + return MP_OBJ_NEW_SMALL_INT(MP_SOFT_RESET); + } switch (esp_reset_reason()) { case ESP_RST_POWERON: case ESP_RST_BROWNOUT: @@ -171,6 +176,15 @@ STATIC mp_obj_t machine_reset_cause(size_t n_args, const mp_obj_t *pos_args, mp_ } STATIC MP_DEFINE_CONST_FUN_OBJ_KW(machine_reset_cause_obj, 0, machine_reset_cause); +void machine_init(void) { + is_soft_reset = 0; +} + +void machine_deinit(void) { + // we are doing a soft-reset so change the reset_cause + is_soft_reset = 1; +} + STATIC mp_obj_t machine_wake_reason(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { return MP_OBJ_NEW_SMALL_INT(esp_sleep_get_wakeup_cause()); } diff --git a/ports/esp32/modmachine.h b/ports/esp32/modmachine.h index 98b36e32b..3e99e1120 100644 --- a/ports/esp32/modmachine.h +++ b/ports/esp32/modmachine.h @@ -22,6 +22,8 @@ extern const mp_obj_type_t machine_uart_type; extern const mp_obj_type_t machine_rtc_type; extern const mp_obj_type_t machine_sdcard_type; +void machine_init(void); +void machine_deinit(void); void machine_pins_init(void); void machine_pins_deinit(void); void machine_timer_deinit_all(void); |
