Skip to content

Commit

Permalink
ports/all: deinit builtin modules on soft-reset.
Browse files Browse the repository at this point in the history
Signed-off-by: Andrew Leech <[email protected]>
  • Loading branch information
pi-anl committed Oct 23, 2024
1 parent f66ea31 commit 27f2d94
Show file tree
Hide file tree
Showing 11 changed files with 41 additions and 0 deletions.
4 changes: 4 additions & 0 deletions ports/esp32/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
3 changes: 3 additions & 0 deletions ports/esp8266/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions ports/mimxrt/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
5 changes: 5 additions & 0 deletions ports/nrf/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
3 changes: 3 additions & 0 deletions ports/qemu/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
4 changes: 4 additions & 0 deletions ports/renesas-ra/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
4 changes: 4 additions & 0 deletions ports/rp2/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
3 changes: 3 additions & 0 deletions ports/samd/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
4 changes: 4 additions & 0 deletions ports/stm32/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
4 changes: 4 additions & 0 deletions ports/unix/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions ports/zephyr/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down

0 comments on commit 27f2d94

Please sign in to comment.