From 27f2d9417b0736ec37ed10086615779659bab02c Mon Sep 17 00:00:00 2001 From: Andrew Leech Date: Wed, 23 Oct 2024 11:51:46 +1100 Subject: [PATCH] ports/all: deinit builtin modules on soft-reset. Signed-off-by: Andrew Leech --- ports/esp32/main.c | 4 ++++ ports/esp8266/main.c | 3 +++ ports/mimxrt/main.c | 3 +++ ports/nrf/main.c | 5 +++++ ports/qemu/main.c | 3 +++ ports/renesas-ra/main.c | 4 ++++ ports/rp2/main.c | 4 ++++ ports/samd/main.c | 3 +++ ports/stm32/main.c | 4 ++++ ports/unix/main.c | 4 ++++ ports/zephyr/main.c | 4 ++++ 11 files changed, 41 insertions(+) diff --git a/ports/esp32/main.c b/ports/esp32/main.c index 03dc0807a025c..84fc1736288bd 100644 --- a/ports/esp32/main.c +++ b/ports/esp32/main.c @@ -182,6 +182,10 @@ void mp_task(void *pvParameter) { mp_thread_deinit(); #endif + #if MICROPY_MODULE_BUILTIN_INIT + mp_module_builtin_deinit(); + #endif + gc_sweep_all(); // Free any native code pointers that point to iRAM. diff --git a/ports/esp8266/main.c b/ports/esp8266/main.c index 2dd7c1dece3a4..6432979c50be2 100644 --- a/ports/esp8266/main.c +++ b/ports/esp8266/main.c @@ -88,6 +88,9 @@ static void mp_reset(void) { } void soft_reset(void) { + #if MICROPY_MODULE_BUILTIN_INIT + mp_module_builtin_deinit(); + #endif gc_sweep_all(); mp_hal_stdout_tx_str("MPY: soft reboot\r\n"); mp_hal_delay_us(10000); // allow UART to flush output diff --git a/ports/mimxrt/main.c b/ports/mimxrt/main.c index adb071a7fee8f..85b60c3e07f6c 100644 --- a/ports/mimxrt/main.c +++ b/ports/mimxrt/main.c @@ -159,6 +159,9 @@ int main(void) { machine_uart_deinit_all(); machine_pwm_deinit_all(); soft_timer_deinit(); + #if MICROPY_MODULE_BUILTIN_INIT + mp_module_builtin_deinit(); + #endif gc_sweep_all(); mp_deinit(); } diff --git a/ports/nrf/main.c b/ports/nrf/main.c index 29550bd77a748..8041f027d8740 100644 --- a/ports/nrf/main.c +++ b/ports/nrf/main.c @@ -292,6 +292,11 @@ void NORETURN _start(void) { pwm_deinit_all(); #endif + #if MICROPY_MODULE_BUILTIN_INIT + mp_module_builtin_deinit(); + #endif + + gc_sweep_all(); mp_deinit(); printf("MPY: soft reboot\n"); diff --git a/ports/qemu/main.c b/ports/qemu/main.c index 042106580407d..7db022a6445f6 100644 --- a/ports/qemu/main.c +++ b/ports/qemu/main.c @@ -60,6 +60,9 @@ int main(int argc, char **argv) { mp_printf(&mp_plat_print, "MPY: soft reboot\n"); + #if MICROPY_MODULE_BUILTIN_INIT + mp_module_builtin_deinit(); + #endif gc_sweep_all(); mp_deinit(); } diff --git a/ports/renesas-ra/main.c b/ports/renesas-ra/main.c index febb7b6d7aaa3..45b6d1f041030 100644 --- a/ports/renesas-ra/main.c +++ b/ports/renesas-ra/main.c @@ -435,6 +435,10 @@ int main(void) { pyb_thread_deinit(); #endif + #if MICROPY_MODULE_BUILTIN_INIT + mp_module_builtin_deinit(); + #endif + MICROPY_BOARD_END_SOFT_RESET(&state); gc_sweep_all(); diff --git a/ports/rp2/main.c b/ports/rp2/main.c index d6bf448267152..9211e300610ae 100644 --- a/ports/rp2/main.c +++ b/ports/rp2/main.c @@ -242,6 +242,10 @@ int main(int argc, char **argv) { mp_usbd_deinit(); #endif + #if MICROPY_MODULE_BUILTIN_INIT + mp_module_builtin_deinit(); + #endif + // Hook for resetting anything right at the end of a soft reset command. MICROPY_BOARD_END_SOFT_RESET(); diff --git a/ports/samd/main.c b/ports/samd/main.c index 2bbaf63e6e4c5..f3774aef4f2a2 100644 --- a/ports/samd/main.c +++ b/ports/samd/main.c @@ -98,6 +98,9 @@ void samd_main(void) { #if MICROPY_HW_ENABLE_USB_RUNTIME_DEVICE mp_usbd_deinit(); #endif + #if MICROPY_MODULE_BUILTIN_INIT + mp_module_builtin_deinit(); + #endif gc_sweep_all(); #if MICROPY_PY_MACHINE_I2C || MICROPY_PY_MACHINE_SPI || MICROPY_PY_MACHINE_UART sercom_deinit_all(); diff --git a/ports/stm32/main.c b/ports/stm32/main.c index df483602dc901..bd2f64d79eaa3 100644 --- a/ports/stm32/main.c +++ b/ports/stm32/main.c @@ -698,6 +698,10 @@ void stm32_main(uint32_t reset_mode) { MP_STATE_PORT(pyb_stdio_uart) = NULL; #endif + #if MICROPY_MODULE_BUILTIN_INIT + mp_module_builtin_deinit(); + #endif + MICROPY_BOARD_END_SOFT_RESET(&state); gc_sweep_all(); diff --git a/ports/unix/main.c b/ports/unix/main.c index 58fa3ff589a55..a66a3aba263ab 100644 --- a/ports/unix/main.c +++ b/ports/unix/main.c @@ -774,6 +774,10 @@ MP_NOINLINE int main_(int argc, char **argv) { mp_thread_deinit(); #endif + #if MICROPY_MODULE_BUILTIN_INIT + mp_module_builtin_deinit(); + #endif + #if defined(MICROPY_UNIX_COVERAGE) gc_sweep_all(); #endif diff --git a/ports/zephyr/main.c b/ports/zephyr/main.c index 9fae2b3a873e5..6d73a1d6d4363 100644 --- a/ports/zephyr/main.c +++ b/ports/zephyr/main.c @@ -172,6 +172,10 @@ int real_main(void) { gc_collect(); #endif + #if MICROPY_MODULE_BUILTIN_INIT + mp_module_builtin_deinit(); + #endif + gc_sweep_all(); mp_deinit();