diff options
author | Damien George <damien@micropython.org> | 2025-06-23 12:52:05 +1000 |
---|---|---|
committer | Damien George <damien@micropython.org> | 2025-07-08 10:10:16 +1000 |
commit | d9b4327c66d455f4654ab4f223067f3e20440333 (patch) | |
tree | 583edb52467a90e8fa4931c878779b1910342cfa | |
parent | 16d9e704aeb48d9507c56bf90f565c0b19b3fb79 (diff) |
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 <damien@micropython.org>
-rw-r--r-- | ports/zephyr/main.c | 18 |
1 files 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(); |