From d9b4327c66d455f4654ab4f223067f3e20440333 Mon Sep 17 00:00:00 2001 From: Damien George Date: Mon, 23 Jun 2025 12:52:05 +1000 Subject: [PATCH] zephyr/main: Execute boot.py and main.py like other ports. Changes here make the zephyr port act the same as other ports for the start up and shut down sequence: - `boot.py` is executed if it exists, and can force a soft reset - `main.py` is only executed if in friendly REPL and if `boot.py` executed successfully; and it can also force a soft reset - print "MPY: " before "soft reboot" on soft reset Signed-off-by: Damien George --- ports/zephyr/main.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/ports/zephyr/main.c b/ports/zephyr/main.c index 45af7b0c7..9addd7d6c 100644 --- a/ports/zephyr/main.c +++ b/ports/zephyr/main.c @@ -156,7 +156,17 @@ soft_reset: #endif #if MICROPY_MODULE_FROZEN || MICROPY_VFS - pyexec_file_if_exists("main.py"); + // Execute user scripts. + int ret = pyexec_file_if_exists("boot.py"); + if (ret & PYEXEC_FORCED_EXIT) { + goto soft_reset_exit; + } + if (pyexec_mode_kind == PYEXEC_MODE_FRIENDLY_REPL && ret != 0) { + ret = pyexec_file_if_exists("main.py"); + if (ret & PYEXEC_FORCED_EXIT) { + goto soft_reset_exit; + } + } #endif for (;;) { @@ -171,7 +181,11 @@ soft_reset: } } - printf("soft reboot\n"); + #if MICROPY_MODULE_FROZEN || MICROPY_VFS +soft_reset_exit: + #endif + + mp_printf(MP_PYTHON_PRINTER, "MPY: soft reboot\n"); #if MICROPY_PY_BLUETOOTH mp_bluetooth_deinit();