Skip to content

Commit

Permalink
Attempt at a reset behaviour patch
Browse files Browse the repository at this point in the history
  • Loading branch information
ZodiusInfuser committed Jul 21, 2023
1 parent 5d7de62 commit 462ad8f
Show file tree
Hide file tree
Showing 2 changed files with 132 additions and 4 deletions.
10 changes: 6 additions & 4 deletions .github/workflows/micropython.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,9 @@ jobs:
working-directory: micropython
run: |
git submodule update --init lib/pico-sdk
git submodule update --init lib/cyw43-driver
git submodule update --init lib/lwip
git submodule update --init lib/mbedtls
git submodule update --init lib/micropython-lib
git submodule update --init lib/tinyusb
git submodule update --init lib/btstack
- name: Build mpy-cross
if: steps.cache.outputs.cache-hit != 'true'
Expand Down Expand Up @@ -74,7 +71,7 @@ jobs:
BOARD_DIR: "$GITHUB_WORKSPACE/yukon/firmware/${{matrix.board}}"
FILESYSTEM_DIR: "$GITHUB_WORKSPACE/yukon/firmware/filesystem"
FILESYSTEM_SUFFIX: "with-filesystem"
BOARD: "PICO_W"
BOARD: "PIMORONI_YUKON"

steps:
- name: Compiler Cache
Expand Down Expand Up @@ -126,6 +123,11 @@ jobs:
working-directory: micropython
run: git apply "${{env.FIRMWARE_DIR}}/micropython_nano_specs.patch"

- name: "HACK: Yukon Reset Patch"
shell: bash
working-directory: micropython
run: git apply "${{env.FIRMWARE_DIR}}/yukon_reset.patch"

# Install apt packages
- name: Install CCache & Compiler
shell: bash
Expand Down
126 changes: 126 additions & 0 deletions firmware/yukon_reset.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
diff --git a/ports/rp2/main.c b/ports/rp2/main.c
index ff0384b95..d76d2ef42 100644
--- a/ports/rp2/main.c
+++ b/ports/rp2/main.c
@@ -71,6 +71,22 @@ bi_decl(bi_program_feature_group_with_flags(BINARY_INFO_TAG_MICROPYTHON,
BINARY_INFO_ID_MP_FROZEN, "frozen modules",
BI_NAMED_GROUP_SEPARATE_COMMAS | BI_NAMED_GROUP_SORT_ALPHA));

+
+void board_init(void) {
+}
+
+// Do-nothing so not all boards need to provide this function.
+//MP_WEAK void reset_board(void) {
+void board_reset(void) {
+ for (int i = 0; i < NUM_BANK0_GPIOS; ++i) {
+ gpio_init(i);
+ hw_clear_bits(&padsbank0_hw->io[i], PADS_BANK0_GPIO0_IE_BITS |
+ PADS_BANK0_GPIO0_PUE_BITS |
+ PADS_BANK0_GPIO0_PDE_BITS);
+ hw_set_bits(&padsbank0_hw->io[i], PADS_BANK0_GPIO0_OD_BITS);
+ }
+}
+
int main(int argc, char **argv) {
#if MICROPY_HW_ENABLE_UART_REPL
bi_decl(bi_program_feature("UART REPL"))
@@ -144,6 +160,7 @@ int main(int argc, char **argv) {
}
#endif

+ bool run_main = true;
for (;;) {

// Initialise MicroPython runtime.
@@ -166,6 +183,8 @@ int main(int argc, char **argv) {
mod_network_lwip_init();
#endif

+ board_init();
+
// Execute _boot.py to set up the filesystem.
#if MICROPY_VFS_FAT && MICROPY_HW_USB_MSC
pyexec_frozen_module("_boot_fat.py", false);
@@ -173,32 +192,43 @@ int main(int argc, char **argv) {
pyexec_frozen_module("_boot.py", false);
#endif

- // 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 = pyexec_file_if_exists("main.py");
+ if (run_main) {
+ // Execute user scripts.
+ int ret = pyexec_file_if_exists("boot.py");
if (ret & PYEXEC_FORCED_EXIT) {
+ run_main = !(ret & PYEXEC_SKIP_USER_CODE);
goto soft_reset_exit;
}
+ if (pyexec_mode_kind == PYEXEC_MODE_FRIENDLY_REPL) {
+ ret = pyexec_file_if_exists("main.py");
+ if (ret & PYEXEC_FORCED_EXIT) {
+ run_main = !(ret & PYEXEC_SKIP_USER_CODE);
+ goto soft_reset_exit;
+ }
+ }
}
+ run_main = true;

for (;;) {
if (pyexec_mode_kind == PYEXEC_MODE_RAW_REPL) {
- if (pyexec_raw_repl() != 0) {
+ int ret = pyexec_raw_repl();
+ if (ret != 0) {
+ run_main = !(ret & PYEXEC_SKIP_USER_CODE);
break;
}
} else {
- if (pyexec_friendly_repl() != 0) {
+ int ret = pyexec_friendly_repl();
+ if (ret != 0) {
+ run_main = !(ret & PYEXEC_SKIP_USER_CODE);
break;
}
}
+ //mp_printf(MP_PYTHON_PRINTER, "Yukon: repl ended\n");
}

soft_reset_exit:
mp_printf(MP_PYTHON_PRINTER, "MPY: soft reboot\n");
+ board_reset();
#if MICROPY_PY_NETWORK
mod_network_deinit();
#endif
diff --git a/shared/runtime/pyexec.c b/shared/runtime/pyexec.c
index e32150e5e..facd8fb98 100644
--- a/shared/runtime/pyexec.c
+++ b/shared/runtime/pyexec.c
@@ -146,10 +146,12 @@ STATIC int parse_compile_execute(const void *source, mp_parse_input_kind_t input
// check for SystemExit
if (mp_obj_is_subclass_fast(MP_OBJ_FROM_PTR(((mp_obj_base_t *)nlr.ret_val)->type), MP_OBJ_FROM_PTR(&mp_type_SystemExit))) {
// at the moment, the value of SystemExit is unused
- ret = pyexec_system_exit;
+ ret = pyexec_system_exit | PYEXEC_FORCED_EXIT | PYEXEC_SKIP_USER_CODE;
} else {
mp_obj_print_exception(&mp_plat_print, MP_OBJ_FROM_PTR(nlr.ret_val));
- ret = 0;
+ ret = 0 | PYEXEC_FORCED_EXIT | PYEXEC_SKIP_USER_CODE;
}
}

diff --git a/shared/runtime/pyexec.h b/shared/runtime/pyexec.h
index 64c5ef943..6a2cd8b8f 100644
--- a/shared/runtime/pyexec.h
+++ b/shared/runtime/pyexec.h
@@ -41,6 +41,7 @@ extern pyexec_mode_kind_t pyexec_mode_kind;
extern int pyexec_system_exit;

#define PYEXEC_FORCED_EXIT (0x100)
+#define PYEXEC_SKIP_USER_CODE (0x200)

int pyexec_raw_repl(void);
int pyexec_friendly_repl(void);

0 comments on commit 462ad8f

Please sign in to comment.