diff --git a/ports/mimxrt/main.c b/ports/mimxrt/main.c index 0b92a3496..3a947fd9b 100644 --- a/ports/mimxrt/main.c +++ b/ports/mimxrt/main.c @@ -68,13 +68,12 @@ #include "omv_boardconfig.h" #include "framebuffer.h" #include "omv_csi.h" -#include "usbdbg.h" -#include "tinyusb_debug.h" #include "fb_alloc.h" #include "dma_alloc.h" #include "file_utils.h" #include "mp_utils.h" #include "mimxrt_hal.h" +#include "omv_protocol.h" int main(void) { bool first_soft_reset = true; @@ -110,7 +109,6 @@ soft_reset: #ifdef IMLIB_ENABLE_IMAGE_FILE_IO file_buffer_init0(); #endif - usbdbg_init(); machine_adc_init(); #if MICROPY_PY_MACHINE_SDCARD machine_sdcard_init0(); @@ -119,6 +117,7 @@ soft_reset: machine_i2s_init0(); #endif machine_rtc_start(); + omv_protocol_init_default(); #if MICROPY_PY_LWIP // lwIP can only be initialized once, because the system timeout @@ -173,22 +172,18 @@ soft_reset: tusb_init(); } - // Run boot.py script. - bool interrupted = mp_exec_bootscript("boot.py", true); - - // Run main.py script on first soft-reset. - if (first_soft_reset && !interrupted && mp_vfs_import_stat("main.py")) { - mp_exec_bootscript("main.py", true); - goto soft_reset_exit; + // Run boot.py every reset and main.py on first soft-reset + if (pyexec_file_if_exists("boot.py") && first_soft_reset) { + pyexec_file_if_exists("main.py"); } - // If there's no script ready, just re-exec REPL - while (!usbdbg_script_ready()) { + while (!omv_protocol_exec_script()) { nlr_buf_t nlr; + if (nlr_push(&nlr) == 0) { - // enable IDE interrupt - usbdbg_set_irq_enabled(true); - // run REPL + // Enable Ctrl+C to interrupt script or REPL. + mp_hal_set_interrupt_char(CHAR_CTRL_C); + if (pyexec_mode_kind == PYEXEC_MODE_RAW_REPL) { if (pyexec_raw_repl() != 0) { break; @@ -202,22 +197,8 @@ soft_reset: } } - if (usbdbg_script_ready()) { - nlr_buf_t nlr; - 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); - } - } - -soft_reset_exit: + // soft reset + mp_hal_set_interrupt_char(-1); mp_printf(MP_PYTHON_PRINTER, "MPY: soft reboot\n"); #if MICROPY_PY_CSI omv_csi_abort_all(); diff --git a/ports/mimxrt/mimxrt.ld.S b/ports/mimxrt/mimxrt.ld.S index 975b6c1ce..4e98304d0 100644 --- a/ports/mimxrt/mimxrt.ld.S +++ b/ports/mimxrt/mimxrt.ld.S @@ -105,7 +105,7 @@ SECTIONS .text : { . = ALIGN(4); - *(EXCLUDE_FILE(*fsl_flexspi.o *gc.o *vm.o *parse*.o *runtime*.o *map.o *mpirq.o ) .text*) + *(EXCLUDE_FILE(*fsl_flexspi.o *gc.o *vm.o *parse*.o *runtime*.o *mpirq.o ) .text*) *(.rodata) *(.rodata*) *(.glue_7) diff --git a/ports/mimxrt/omv_mpconfigport.h b/ports/mimxrt/omv_mpconfigport.h index acc7eb752..7083d4dc3 100644 --- a/ports/mimxrt/omv_mpconfigport.h +++ b/ports/mimxrt/omv_mpconfigport.h @@ -29,6 +29,18 @@ fb_alloc_free_till_mark(); \ } while (0); +#define MICROPY_BOARD_BEFORE_PYTHON_EXEC(input_kind, exec_flags) \ + do { \ + extern void stdio_channel_pyexec_hook(bool); \ + stdio_channel_pyexec_hook(true); \ + } while (0); + +#define MICROPY_BOARD_AFTER_PYTHON_EXEC(input_kind, exec_flags, nlr, ret) \ + do { \ + extern void stdio_channel_pyexec_hook(bool); \ + stdio_channel_pyexec_hook(false); \ + } while (0); + #define MICROPY_ENABLE_VM_ABORT (1) #define MICROPY_PY_NETWORK_PPP_LWIP (0) #define MICROPY_PY_MACHINE_UART_IRQ (0) diff --git a/ports/mimxrt/omv_portconfig.mk b/ports/mimxrt/omv_portconfig.mk index 7ea176d04..81a3d82a0 100644 --- a/ports/mimxrt/omv_portconfig.mk +++ b/ports/mimxrt/omv_portconfig.mk @@ -76,8 +76,8 @@ LDFLAGS = -mthumb \ -mabi=aapcs-linux \ -Wl,--print-memory-usage \ -Wl,--gc-sections \ - -Wl,--wrap=mp_usbd_task \ -Wl,--wrap=tud_cdc_rx_cb \ + -Wl,--wrap=tud_cdc_line_state_cb \ -Wl,--wrap=mp_hal_stdio_poll \ -Wl,--wrap=mp_hal_stdout_tx_strn \ -Wl,-T$(BUILD)/$(LDSCRIPT).lds \ @@ -140,6 +140,7 @@ include lib/imlib/imlib.mk include lib/tflm/tflm.mk include ports/ports.mk include common/micropy.mk +include protocol/protocol.mk # Firmware objects from port. MPY_FIRM_OBJ += $(addprefix $(BUILD)/$(MICROPY_DIR)/,\