Merge pull request #1817 from openmv/exception_fixes

ports/All: Improve script execution and exception handling.
This commit is contained in:
Ibrahim Abdelkader 2023-04-07 17:40:16 +02:00 committed by GitHub
commit 27db34d8d5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 53 additions and 28 deletions

@ -1 +1 @@
Subproject commit 01a75d8501bc60e969d7fb4c1096c208693a2609
Subproject commit 887c134328f75d46215b85275af8eccbc46afd9d

View File

@ -86,6 +86,11 @@ vstr_t *usbdbg_get_script()
return &script_buf;
}
bool usbdbg_is_busy()
{
return cmd != USBDBG_NONE;
}
void usbdbg_set_script_running(bool running)
{
script_running = running;

View File

@ -55,6 +55,7 @@ void usbdbg_init();
void usbdbg_wait_for_command(uint32_t timeout);
bool usbdbg_script_ready();
vstr_t *usbdbg_get_script();
bool usbdbg_is_busy();
bool usbdbg_get_irq_enabled();
void usbdbg_set_irq_enabled(bool enabled);
void usbdbg_set_script_running(bool running);

View File

@ -296,10 +296,9 @@ soft_reset:
nlr_buf_t nlr;
if (nlr_push(&nlr) == 0) {
// enable IDE interrupt
// Enable IDE interrupt
usbdbg_set_irq_enabled(true);
//__WFI();
// run REPL
if (pyexec_mode_kind == PYEXEC_MODE_RAW_REPL) {
if (pyexec_raw_repl() != 0) {
@ -320,35 +319,37 @@ soft_reset:
if (nlr_push(&nlr) == 0) {
// Enable IDE interrupt
usbdbg_set_irq_enabled(true);
// 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);
// Wait for the current command to finish.
usbdbg_wait_for_command(1000);
// Disable IDE interrupts
usbdbg_set_irq_enabled(false);
nlr_pop();
}
}
usbdbg_wait_for_command(1000);
usbdbg_set_irq_enabled(false);
mp_deinit();
printf("MPY: soft reboot\n");
#if MICROPY_PY_AUDIO
py_audio_deinit();
#endif
#if BLUETOOTH_SD
sd_softdevice_disable();
#endif
#if defined(MICROPY_BOARD_DEINIT)
MICROPY_BOARD_DEINIT();
#endif
mp_deinit();
goto soft_reset;
return 0;

View File

@ -267,15 +267,23 @@ soft_reset:
usbdbg_set_irq_enabled(true);
// 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);
// Wait for the current command to finish.
usbdbg_wait_for_command(1000);
// Disable IDE interrupts
usbdbg_set_irq_enabled(false);
nlr_pop();
}
}
mp_printf(MP_PYTHON_PRINTER, "MPY: soft reboot\n");
#if MICROPY_PY_AUDIO

View File

@ -607,27 +607,37 @@ 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);
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) {
// Wait for the current command to finish.
usbdbg_wait_for_command(1000);
// Disable IDE interrupts
usbdbg_set_irq_enabled(false);
nlr_pop();
}
}
} while (openmv_config.wifidbg == true);
}
// soft reset
storage_flush();