ports/mimxrt: Switch to new protocol.

Signed-off-by: iabdalkader <i.abdalkader@gmail.com>
This commit is contained in:
iabdalkader 2025-09-03 11:39:56 +02:00
parent e9d5e3bfbf
commit 0ee4824c90
4 changed files with 27 additions and 33 deletions

View File

@ -68,13 +68,12 @@
#include "omv_boardconfig.h" #include "omv_boardconfig.h"
#include "framebuffer.h" #include "framebuffer.h"
#include "omv_csi.h" #include "omv_csi.h"
#include "usbdbg.h"
#include "tinyusb_debug.h"
#include "fb_alloc.h" #include "fb_alloc.h"
#include "dma_alloc.h" #include "dma_alloc.h"
#include "file_utils.h" #include "file_utils.h"
#include "mp_utils.h" #include "mp_utils.h"
#include "mimxrt_hal.h" #include "mimxrt_hal.h"
#include "omv_protocol.h"
int main(void) { int main(void) {
bool first_soft_reset = true; bool first_soft_reset = true;
@ -110,7 +109,6 @@ soft_reset:
#ifdef IMLIB_ENABLE_IMAGE_FILE_IO #ifdef IMLIB_ENABLE_IMAGE_FILE_IO
file_buffer_init0(); file_buffer_init0();
#endif #endif
usbdbg_init();
machine_adc_init(); machine_adc_init();
#if MICROPY_PY_MACHINE_SDCARD #if MICROPY_PY_MACHINE_SDCARD
machine_sdcard_init0(); machine_sdcard_init0();
@ -119,6 +117,7 @@ soft_reset:
machine_i2s_init0(); machine_i2s_init0();
#endif #endif
machine_rtc_start(); machine_rtc_start();
omv_protocol_init_default();
#if MICROPY_PY_LWIP #if MICROPY_PY_LWIP
// lwIP can only be initialized once, because the system timeout // lwIP can only be initialized once, because the system timeout
@ -173,22 +172,18 @@ soft_reset:
tusb_init(); tusb_init();
} }
// Run boot.py script. // Run boot.py every reset and main.py on first soft-reset
bool interrupted = mp_exec_bootscript("boot.py", true); if (pyexec_file_if_exists("boot.py") && first_soft_reset) {
pyexec_file_if_exists("main.py");
// 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;
} }
// If there's no script ready, just re-exec REPL while (!omv_protocol_exec_script()) {
while (!usbdbg_script_ready()) {
nlr_buf_t nlr; nlr_buf_t nlr;
if (nlr_push(&nlr) == 0) { if (nlr_push(&nlr) == 0) {
// enable IDE interrupt // Enable Ctrl+C to interrupt script or REPL.
usbdbg_set_irq_enabled(true); mp_hal_set_interrupt_char(CHAR_CTRL_C);
// run REPL
if (pyexec_mode_kind == PYEXEC_MODE_RAW_REPL) { if (pyexec_mode_kind == PYEXEC_MODE_RAW_REPL) {
if (pyexec_raw_repl() != 0) { if (pyexec_raw_repl() != 0) {
break; break;
@ -202,22 +197,8 @@ soft_reset:
} }
} }
if (usbdbg_script_ready()) { // soft reset
nlr_buf_t nlr; mp_hal_set_interrupt_char(-1);
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:
mp_printf(MP_PYTHON_PRINTER, "MPY: soft reboot\n"); mp_printf(MP_PYTHON_PRINTER, "MPY: soft reboot\n");
#if MICROPY_PY_CSI #if MICROPY_PY_CSI
omv_csi_abort_all(); omv_csi_abort_all();

View File

@ -105,7 +105,7 @@ SECTIONS
.text : .text :
{ {
. = ALIGN(4); . = 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)
*(.rodata*) *(.rodata*)
*(.glue_7) *(.glue_7)

View File

@ -29,6 +29,18 @@
fb_alloc_free_till_mark(); \ fb_alloc_free_till_mark(); \
} while (0); } 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_ENABLE_VM_ABORT (1)
#define MICROPY_PY_NETWORK_PPP_LWIP (0) #define MICROPY_PY_NETWORK_PPP_LWIP (0)
#define MICROPY_PY_MACHINE_UART_IRQ (0) #define MICROPY_PY_MACHINE_UART_IRQ (0)

View File

@ -76,8 +76,8 @@ LDFLAGS = -mthumb \
-mabi=aapcs-linux \ -mabi=aapcs-linux \
-Wl,--print-memory-usage \ -Wl,--print-memory-usage \
-Wl,--gc-sections \ -Wl,--gc-sections \
-Wl,--wrap=mp_usbd_task \
-Wl,--wrap=tud_cdc_rx_cb \ -Wl,--wrap=tud_cdc_rx_cb \
-Wl,--wrap=tud_cdc_line_state_cb \
-Wl,--wrap=mp_hal_stdio_poll \ -Wl,--wrap=mp_hal_stdio_poll \
-Wl,--wrap=mp_hal_stdout_tx_strn \ -Wl,--wrap=mp_hal_stdout_tx_strn \
-Wl,-T$(BUILD)/$(LDSCRIPT).lds \ -Wl,-T$(BUILD)/$(LDSCRIPT).lds \
@ -140,6 +140,7 @@ include lib/imlib/imlib.mk
include lib/tflm/tflm.mk include lib/tflm/tflm.mk
include ports/ports.mk include ports/ports.mk
include common/micropy.mk include common/micropy.mk
include protocol/protocol.mk
# Firmware objects from port. # Firmware objects from port.
MPY_FIRM_OBJ += $(addprefix $(BUILD)/$(MICROPY_DIR)/,\ MPY_FIRM_OBJ += $(addprefix $(BUILD)/$(MICROPY_DIR)/,\