Skip to content

Commit 4ef2da1

Browse files
robert-hhdpgeorge
authored andcommitted
samd/main: Use the common execution mode of boot.py and main.py.
Behaviour is: - Do not execute main.py if boot.py failed. - On a forced exit, do a soft reset.
1 parent 45bf25a commit 4ef2da1

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

ports/samd/main.c

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,17 @@ void samd_main(void) {
5151
pyexec_frozen_module("_boot.py");
5252

5353
// Execute user scripts.
54-
pyexec_file_if_exists("boot.py");
55-
pyexec_file_if_exists("main.py");
54+
int ret = pyexec_file_if_exists("boot.py");
55+
if (ret & PYEXEC_FORCED_EXIT) {
56+
goto soft_reset_exit;
57+
}
58+
// Do not execute main.py if boot.py failed
59+
if (pyexec_mode_kind == PYEXEC_MODE_FRIENDLY_REPL && ret != 0) {
60+
ret = pyexec_file_if_exists("main.py");
61+
if (ret & PYEXEC_FORCED_EXIT) {
62+
goto soft_reset_exit;
63+
}
64+
}
5665

5766
for (;;) {
5867
if (pyexec_mode_kind == PYEXEC_MODE_RAW_REPL) {
@@ -66,6 +75,7 @@ void samd_main(void) {
6675
}
6776
}
6877

78+
soft_reset_exit:
6979
mp_printf(MP_PYTHON_PRINTER, "MPY: soft reboot\n");
7080
adc_deinit_all();
7181
pin_irq_deinit_all();

0 commit comments

Comments
 (0)