mirror of
https://github.com/micropython/micropython.git
synced 2026-01-04 19:20:22 +01:00
stm32/boardctrl: Give boards control over execution of boot.py,main.py.
This commit simplifies the customisation of the main MicroPython execution loop (4 macros are reduced to 2), and allows a board to have full control over the execution (or not) of boot.py and main.py. For boards that use the default start-up code, there is no functional change in this commit. Signed-off-by: Damien George <damien@micropython.org>
This commit is contained in:
@@ -469,9 +469,7 @@ void stm32_main(uint32_t reset_mode) {
|
||||
|
||||
boardctrl_state_t state;
|
||||
state.reset_mode = reset_mode;
|
||||
state.run_boot_py = false;
|
||||
state.run_main_py = false;
|
||||
state.last_ret = 0;
|
||||
state.log_soft_reset = false;
|
||||
|
||||
MICROPY_BOARD_BEFORE_SOFT_RESET_LOOP(&state);
|
||||
|
||||
@@ -566,20 +564,11 @@ soft_reset:
|
||||
// reset config variables; they should be set by boot.py
|
||||
MP_STATE_PORT(pyb_config_main) = MP_OBJ_NULL;
|
||||
|
||||
MICROPY_BOARD_BEFORE_BOOT_PY(&state);
|
||||
|
||||
// run boot.py, if it exists
|
||||
// TODO perhaps have pyb.reboot([bootpy]) function to soft-reboot and execute custom boot.py
|
||||
if (state.run_boot_py) {
|
||||
const char *boot_py = "boot.py";
|
||||
state.last_ret = pyexec_file_if_exists(boot_py);
|
||||
if (state.last_ret & PYEXEC_FORCED_EXIT) {
|
||||
goto soft_reset_exit;
|
||||
}
|
||||
// Run boot.py (or whatever else a board configures at this stage).
|
||||
if (MICROPY_BOARD_RUN_BOOT_PY(&state) == BOARDCTRL_GOTO_SOFT_RESET_EXIT) {
|
||||
goto soft_reset_exit;
|
||||
}
|
||||
|
||||
MICROPY_BOARD_AFTER_BOOT_PY(&state);
|
||||
|
||||
// Now we initialise sub-systems that need configuration from boot.py,
|
||||
// or whose initialisation can be safely deferred until after running
|
||||
// boot.py.
|
||||
@@ -613,24 +602,11 @@ soft_reset:
|
||||
|
||||
// At this point everything is fully configured and initialised.
|
||||
|
||||
MICROPY_BOARD_BEFORE_MAIN_PY(&state);
|
||||
|
||||
// Run the main script from the current directory.
|
||||
if (state.run_main_py) {
|
||||
const char *main_py;
|
||||
if (MP_STATE_PORT(pyb_config_main) == MP_OBJ_NULL) {
|
||||
main_py = "main.py";
|
||||
} else {
|
||||
main_py = mp_obj_str_get_str(MP_STATE_PORT(pyb_config_main));
|
||||
}
|
||||
state.last_ret = pyexec_file_if_exists(main_py);
|
||||
if (state.last_ret & PYEXEC_FORCED_EXIT) {
|
||||
goto soft_reset_exit;
|
||||
}
|
||||
// Run main.py (or whatever else a board configures at this stage).
|
||||
if (MICROPY_BOARD_RUN_MAIN_PY(&state) == BOARDCTRL_GOTO_SOFT_RESET_EXIT) {
|
||||
goto soft_reset_exit;
|
||||
}
|
||||
|
||||
MICROPY_BOARD_AFTER_MAIN_PY(&state);
|
||||
|
||||
#if MICROPY_ENABLE_COMPILER
|
||||
// Main script is finished, so now go into REPL mode.
|
||||
// The REPL mode can change, or it can request a soft reset.
|
||||
|
||||
Reference in New Issue
Block a user