ports/alif: Switch to new protocol.

Signed-off-by: iabdalkader <i.abdalkader@gmail.com>
This commit is contained in:
iabdalkader 2025-09-19 18:01:23 +02:00
parent 0718c4bfbd
commit bb517e5cdd
2 changed files with 22 additions and 44 deletions

View File

@ -176,8 +176,8 @@ LDFLAGS = -mthumb \
ifeq ($(MCU_CORE),M55_HP) ifeq ($(MCU_CORE),M55_HP)
# Linker Flags # Linker Flags
LDFLAGS += -Wl,--wrap=mp_usbd_task \ LDFLAGS += -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
endif endif
@ -186,6 +186,7 @@ endif
include lib/cmsis/cmsis.mk include lib/cmsis/cmsis.mk
include lib/alif/alif.mk include lib/alif/alif.mk
include common/common.mk include common/common.mk
include protocol/protocol.mk
include drivers/drivers.mk include drivers/drivers.mk
include lib/imlib/imlib.mk include lib/imlib/imlib.mk
include lib/tflm/tflm.mk include lib/tflm/tflm.mk

View File

@ -69,8 +69,6 @@
#include "omv_boardconfig.h" #include "omv_boardconfig.h"
#include "framebuffer.h" #include "framebuffer.h"
#include "usbdbg.h"
#include "tinyusb_debug.h"
#include "fb_alloc.h" #include "fb_alloc.h"
#include "file_utils.h" #include "file_utils.h"
#include "mp_utils.h" #include "mp_utils.h"
@ -81,6 +79,7 @@
#include "py_audio.h" #include "py_audio.h"
#include "py_imu.h" #include "py_imu.h"
#include "omv_gpio.h" #include "omv_gpio.h"
#include "omv_protocol.h"
NORETURN void __fatal_error(const char *msg); NORETURN void __fatal_error(const char *msg);
extern void machine_pin_irq_deinit(void); extern void machine_pin_irq_deinit(void);
@ -125,9 +124,6 @@ soft_reset:
#ifdef IMLIB_ENABLE_IMAGE_FILE_IO #ifdef IMLIB_ENABLE_IMAGE_FILE_IO
file_buffer_init0(); file_buffer_init0();
#endif #endif
#if CORE_M55_HP
usbdbg_init();
#endif
#if MICROPY_PY_IMU #if MICROPY_PY_IMU
py_imu_init(); py_imu_init();
#endif #endif
@ -138,6 +134,11 @@ soft_reset:
} }
#endif #endif
#if CORE_M55_HP
// Initialize OpenMV protocol
omv_protocol_init_default();
#endif
#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
// list (next_timeout), is only ever reset by BSS clearing. // list (next_timeout), is only ever reset by BSS clearing.
@ -168,17 +169,6 @@ soft_reset:
mod_network_init(); mod_network_init();
#endif #endif
// TODO: _boot on HP uses OSPI which is disabled right now.
#if MICROPY_HW_ENABLE_OSPI || CORE_M55_HE
// Execute _boot.py.
pyexec_frozen_module("_boot.py", false);
#endif
#if MICROPY_HW_ENABLE_OSPI
// Mark the filesystem as an OpenMV storage.
file_ll_touch(".openmv_disk");
#endif
// Initialize TinyUSB after the filesystem is mounted. // Initialize TinyUSB after the filesystem is mounted.
#if MICROPY_HW_ENABLE_USBDEV #if MICROPY_HW_ENABLE_USBDEV
if (!tusb_inited()) { if (!tusb_inited()) {
@ -186,26 +176,25 @@ soft_reset:
} }
#endif #endif
// Run boot.py script. // Execute _boot.py.
bool interrupted = mp_exec_bootscript("boot.py", true); pyexec_frozen_module("_boot.py", false);
// Run main.py script on first soft-reset. // Run boot.py every reset and main.py on first soft-reset
if (first_soft_reset && !interrupted && mp_vfs_import_stat("main.py")) { if (pyexec_file_if_exists("boot.py") && first_soft_reset) {
mp_exec_bootscript("main.py", true); pyexec_file_if_exists("main.py");
goto soft_reset_exit;
} }
#if CORE_M55_HE #if CORE_M55_HE
goto soft_reset_exit; goto soft_reset_exit;
#endif #endif
// 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;
@ -219,22 +208,10 @@ soft_reset:
} }
} }
if (usbdbg_script_ready()) { #if CORE_M55_HE
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_exit:
#endif
mp_hal_set_interrupt_char(-1);
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();