From 2d46e31e8a28309bf58da615be1d8809069c00bf Mon Sep 17 00:00:00 2001 From: iabdalkader Date: Fri, 7 Apr 2023 17:32:31 +0200 Subject: [PATCH] ports/stm32: Improve script execution and exceptions handling. --- src/omv/ports/stm32/main.c | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/src/omv/ports/stm32/main.c b/src/omv/ports/stm32/main.c index e43ee72f0..fa9876a6c 100644 --- a/src/omv/ports/stm32/main.c +++ b/src/omv/ports/stm32/main.c @@ -607,25 +607,35 @@ soft_reset: if (usbdbg_script_ready()) { nlr_buf_t nlr; if (nlr_push(&nlr) == 0) { + // Enable IDE interrupts + usbdbg_set_irq_enabled(true); + #if OMV_ENABLE_WIFIDBG && MICROPY_PY_WINC1500 + wifidbg_set_irq_enabled(openmv_config.wifidbg); + #endif + // Execute the script. + pyexec_str(usbdbg_get_script(), true); + // Disable IDE interrupts + usbdbg_set_irq_enabled(false); + nlr_pop(); + } else { + mp_obj_print_exception(&mp_plat_print, (mp_obj_t)nlr.ret_val); + } + + if (usbdbg_is_busy() && nlr_push(&nlr) == 0) { // Enable IDE interrupt usbdbg_set_irq_enabled(true); #if OMV_ENABLE_WIFIDBG && MICROPY_PY_WINC1500 wifidbg_set_irq_enabled(openmv_config.wifidbg); #endif - - // Execute the script. - pyexec_str(usbdbg_get_script(), true); + // Wait for the current command to finish. + usbdbg_wait_for_command(1000); + // Disable IDE interrupts + usbdbg_set_irq_enabled(false); nlr_pop(); - } else { - mp_obj_print_exception(&mp_plat_print, (mp_obj_t)nlr.ret_val); } } - } while (openmv_config.wifidbg == true); - nlr_buf_t nlr; - if (nlr_push(&nlr) == 0) { - usbdbg_wait_for_command(1000); - } + } while (openmv_config.wifidbg == true); } // soft reset