From 3328290c13d34d7b9c4efb831a7d348edae57d2f Mon Sep 17 00:00:00 2001 From: ZodiusInfuser Date: Tue, 30 Apr 2024 15:58:38 +0100 Subject: [PATCH 1/8] Updates for latest micropython --- .github/workflows/micropython.yml | 4 +- .../drivers/tca9555/machine_pin_tca9555.c | 2 +- firmware/modules/tca9555/tca.c | 53 ++++++++++--------- 3 files changed, 30 insertions(+), 29 deletions(-) diff --git a/.github/workflows/micropython.yml b/.github/workflows/micropython.yml index 9af82b2..4b55351 100644 --- a/.github/workflows/micropython.yml +++ b/.github/workflows/micropython.yml @@ -7,8 +7,8 @@ on: types: [created] env: - MICROPYTHON_VERSION: b88262ce96c3433a02b2c8d984ba01e071b60c1f - PIMORONI_PICO_VERSION: 7678ba5da966c3d8b7238e2b2f4e604ffe377dd6 + MICROPYTHON_VERSION: ae6c33a1dda01d5b36b8f5c9e8e0bd3425ba796a + PIMORONI_PICO_VERSION: dd757171c0d54044e89f2fba5916522307892bad WORKFLOW_VERSION: v2 jobs: diff --git a/firmware/drivers/tca9555/machine_pin_tca9555.c b/firmware/drivers/tca9555/machine_pin_tca9555.c index a1e58b8..2438603 100644 --- a/firmware/drivers/tca9555/machine_pin_tca9555.c +++ b/firmware/drivers/tca9555/machine_pin_tca9555.c @@ -38,7 +38,7 @@ void machine_pin_ext_init(void) { // Read the state of each IO expander pin, as some are initialised as outputs - const mp_map_t *named_map = &pin_board_pins_locals_dict.map; + const mp_map_t *named_map = &machine_pin_board_pins_locals_dict.map; for (uint i = 0; i < named_map->used; i++) { machine_pin_obj_t *pin = (machine_pin_obj_t *)named_map->table[i].value; if(pin->is_ext) { diff --git a/firmware/modules/tca9555/tca.c b/firmware/modules/tca9555/tca.c index acc517f..424c874 100644 --- a/firmware/modules/tca9555/tca.c +++ b/firmware/modules/tca9555/tca.c @@ -2,9 +2,10 @@ #include "py/runtime.h" #include "machine_pin.h" +#include "extmod/modmachine.h" #include "tca9555.h" -STATIC mp_obj_t tca_pin_get_number(mp_obj_t pin_obj) { +static mp_obj_t tca_pin_get_number(mp_obj_t pin_obj) { if (!mp_obj_is_type(pin_obj, &machine_pin_type)) { mp_raise_msg_varg(&mp_type_TypeError, MP_ERROR_TEXT("pin must be of type %q, not %q"), machine_pin_type.name, mp_obj_get_type(pin_obj)->name); } @@ -17,9 +18,9 @@ STATIC mp_obj_t tca_pin_get_number(mp_obj_t pin_obj) { uint8_t tca_gpio = pin->id; return mp_obj_new_int(tca_gpio % TCA9555_GPIO_COUNT); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(tca_pin_get_number_obj, tca_pin_get_number); +static MP_DEFINE_CONST_FUN_OBJ_1(tca_pin_get_number_obj, tca_pin_get_number); -STATIC mp_obj_t tca_pin_get_chip(mp_obj_t pin_obj) { +static mp_obj_t tca_pin_get_chip(mp_obj_t pin_obj) { if (!mp_obj_is_type(pin_obj, &machine_pin_type)) { mp_raise_msg_varg(&mp_type_TypeError, MP_ERROR_TEXT("pin must be of type %q, not %q"), machine_pin_type.name, mp_obj_get_type(pin_obj)->name); } @@ -32,9 +33,9 @@ STATIC mp_obj_t tca_pin_get_chip(mp_obj_t pin_obj) { uint8_t tca_gpio = pin->id; return mp_obj_new_int(CHIP_FROM_GPIO(tca_gpio)); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(tca_pin_get_chip_obj, tca_pin_get_chip); +static MP_DEFINE_CONST_FUN_OBJ_1(tca_pin_get_chip_obj, tca_pin_get_chip); -STATIC mp_obj_t tca_pin_change_output_mask(mp_obj_t chip_obj, mp_obj_t mask_obj, mp_obj_t state_obj) { +static mp_obj_t tca_pin_change_output_mask(mp_obj_t chip_obj, mp_obj_t mask_obj, mp_obj_t state_obj) { int chip = mp_obj_get_int(chip_obj); int mask = mp_obj_get_int(mask_obj); int state = mp_obj_get_int(state_obj); @@ -52,9 +53,9 @@ STATIC mp_obj_t tca_pin_change_output_mask(mp_obj_t chip_obj, mp_obj_t mask_obj, return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_3(tca_pin_change_output_mask_obj, tca_pin_change_output_mask); +static MP_DEFINE_CONST_FUN_OBJ_3(tca_pin_change_output_mask_obj, tca_pin_change_output_mask); -STATIC mp_obj_t tca_pin_change_config_mask(mp_obj_t chip_obj, mp_obj_t mask_obj, mp_obj_t state_obj) { +static mp_obj_t tca_pin_change_config_mask(mp_obj_t chip_obj, mp_obj_t mask_obj, mp_obj_t state_obj) { int chip = mp_obj_get_int(chip_obj); int mask = mp_obj_get_int(mask_obj); int state = mp_obj_get_int(state_obj); @@ -72,9 +73,9 @@ STATIC mp_obj_t tca_pin_change_config_mask(mp_obj_t chip_obj, mp_obj_t mask_obj, return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_3(tca_pin_change_config_mask_obj, tca_pin_change_config_mask); +static MP_DEFINE_CONST_FUN_OBJ_3(tca_pin_change_config_mask_obj, tca_pin_change_config_mask); -STATIC mp_obj_t tca_pin_change_polarity_mask(mp_obj_t chip_obj, mp_obj_t mask_obj, mp_obj_t state_obj) { +static mp_obj_t tca_pin_change_polarity_mask(mp_obj_t chip_obj, mp_obj_t mask_obj, mp_obj_t state_obj) { int chip = mp_obj_get_int(chip_obj); int mask = mp_obj_get_int(mask_obj); int state = mp_obj_get_int(state_obj); @@ -92,10 +93,10 @@ STATIC mp_obj_t tca_pin_change_polarity_mask(mp_obj_t chip_obj, mp_obj_t mask_ob return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_3(tca_pin_change_polarity_mask_obj, tca_pin_change_polarity_mask); +static MP_DEFINE_CONST_FUN_OBJ_3(tca_pin_change_polarity_mask_obj, tca_pin_change_polarity_mask); #if TCA9555_READ_INTERNALS -STATIC mp_obj_t tca_port_read_input_state(mp_obj_t chip_obj) { +static mp_obj_t tca_port_read_input_state(mp_obj_t chip_obj) { int chip = mp_obj_get_int(chip_obj); if (chip < 0 || chip >= TCA9555_CHIP_COUNT) { mp_raise_msg_varg(&mp_type_ValueError, MP_ERROR_TEXT("chip can only be 0 to %d"), TCA9555_CHIP_COUNT - 1); @@ -103,9 +104,9 @@ STATIC mp_obj_t tca_port_read_input_state(mp_obj_t chip_obj) { return mp_obj_new_int(tca_get_input_port(chip)); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(tca_port_read_input_state_obj, tca_port_read_input_state); +static MP_DEFINE_CONST_FUN_OBJ_1(tca_port_read_input_state_obj, tca_port_read_input_state); -STATIC mp_obj_t tca_port_read_output_state(mp_obj_t chip_obj) { +static mp_obj_t tca_port_read_output_state(mp_obj_t chip_obj) { int chip = mp_obj_get_int(chip_obj); if (chip < 0 || chip >= TCA9555_CHIP_COUNT) { mp_raise_msg_varg(&mp_type_ValueError, MP_ERROR_TEXT("chip can only be 0 to %d"), TCA9555_CHIP_COUNT - 1); @@ -113,9 +114,9 @@ STATIC mp_obj_t tca_port_read_output_state(mp_obj_t chip_obj) { return mp_obj_new_int(tca_get_output_port(chip)); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(tca_port_read_output_state_obj, tca_port_read_output_state); +static MP_DEFINE_CONST_FUN_OBJ_1(tca_port_read_output_state_obj, tca_port_read_output_state); -STATIC mp_obj_t tca_port_read_config_state(mp_obj_t chip_obj) { +static mp_obj_t tca_port_read_config_state(mp_obj_t chip_obj) { int chip = mp_obj_get_int(chip_obj); if (chip < 0 || chip >= TCA9555_CHIP_COUNT) { mp_raise_msg_varg(&mp_type_ValueError, MP_ERROR_TEXT("chip can only be 0 to %d"), TCA9555_CHIP_COUNT - 1); @@ -123,9 +124,9 @@ STATIC mp_obj_t tca_port_read_config_state(mp_obj_t chip_obj) { return mp_obj_new_int(tca_get_config_port(chip)); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(tca_port_read_config_state_obj, tca_port_read_config_state); +static MP_DEFINE_CONST_FUN_OBJ_1(tca_port_read_config_state_obj, tca_port_read_config_state); -STATIC mp_obj_t tca_port_read_polarity_state(mp_obj_t chip_obj) { +static mp_obj_t tca_port_read_polarity_state(mp_obj_t chip_obj) { int chip = mp_obj_get_int(chip_obj); if (chip < 0 || chip >= TCA9555_CHIP_COUNT) { mp_raise_msg_varg(&mp_type_ValueError, MP_ERROR_TEXT("chip can only be 0 to %d"), TCA9555_CHIP_COUNT - 1); @@ -133,10 +134,10 @@ STATIC mp_obj_t tca_port_read_polarity_state(mp_obj_t chip_obj) { return mp_obj_new_int(tca_get_polarity_port(chip)); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(tca_port_read_polarity_state_obj, tca_port_read_polarity_state); +static MP_DEFINE_CONST_FUN_OBJ_1(tca_port_read_polarity_state_obj, tca_port_read_polarity_state); #if TCA9555_LOCAL_MEMORY -STATIC mp_obj_t tca_port_stored_output_state(mp_obj_t chip_obj) { +static mp_obj_t tca_port_stored_output_state(mp_obj_t chip_obj) { int chip = mp_obj_get_int(chip_obj); if (chip < 0 || chip >= TCA9555_CHIP_COUNT) { mp_raise_msg_varg(&mp_type_ValueError, MP_ERROR_TEXT("chip can only be 0 to %d"), TCA9555_CHIP_COUNT - 1); @@ -144,9 +145,9 @@ STATIC mp_obj_t tca_port_stored_output_state(mp_obj_t chip_obj) { return mp_obj_new_int((tca9555_output_state[HIGH_BYTE(chip)] << 8) | tca9555_output_state[LOW_BYTE(chip)]); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(tca_port_stored_output_state_obj, tca_port_stored_output_state); +static MP_DEFINE_CONST_FUN_OBJ_1(tca_port_stored_output_state_obj, tca_port_stored_output_state); -STATIC mp_obj_t tca_port_stored_config_state(mp_obj_t chip_obj) { +static mp_obj_t tca_port_stored_config_state(mp_obj_t chip_obj) { int chip = mp_obj_get_int(chip_obj); if (chip < 0 || chip >= TCA9555_CHIP_COUNT) { mp_raise_msg_varg(&mp_type_ValueError, MP_ERROR_TEXT("chip can only be 0 to %d"), TCA9555_CHIP_COUNT - 1); @@ -154,9 +155,9 @@ STATIC mp_obj_t tca_port_stored_config_state(mp_obj_t chip_obj) { return mp_obj_new_int((tca9555_config_state[HIGH_BYTE(chip)] << 8) | tca9555_config_state[LOW_BYTE(chip)]); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(tca_port_stored_config_state_obj, tca_port_stored_config_state); +static MP_DEFINE_CONST_FUN_OBJ_1(tca_port_stored_config_state_obj, tca_port_stored_config_state); -STATIC mp_obj_t tca_port_stored_polarity_state(mp_obj_t chip_obj) { +static mp_obj_t tca_port_stored_polarity_state(mp_obj_t chip_obj) { int chip = mp_obj_get_int(chip_obj); if (chip < 0 || chip >= TCA9555_CHIP_COUNT) { mp_raise_msg_varg(&mp_type_ValueError, MP_ERROR_TEXT("chip can only be 0 to %d"), TCA9555_CHIP_COUNT - 1); @@ -164,7 +165,7 @@ STATIC mp_obj_t tca_port_stored_polarity_state(mp_obj_t chip_obj) { return mp_obj_new_int((tca9555_polarity_state[HIGH_BYTE(chip)] << 8) | tca9555_polarity_state[LOW_BYTE(chip)]); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(tca_port_stored_polarity_state_obj, tca_port_stored_polarity_state); +static MP_DEFINE_CONST_FUN_OBJ_1(tca_port_stored_polarity_state_obj, tca_port_stored_polarity_state); #endif #endif @@ -173,7 +174,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(tca_port_stored_polarity_state_obj, tca_port_st // and the MicroPython object reference. // All identifiers and strings are written as MP_QSTR_xxx and will be // optimized to word-sized integers by the build system (interned strings). -STATIC const mp_rom_map_elem_t tca_module_globals_table[] = { +static const mp_rom_map_elem_t tca_module_globals_table[] = { { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_tca) }, { MP_ROM_QSTR(MP_QSTR_get_number), &tca_pin_get_number_obj }, { MP_ROM_QSTR(MP_QSTR_get_chip), &tca_pin_get_chip_obj }, @@ -192,7 +193,7 @@ STATIC const mp_rom_map_elem_t tca_module_globals_table[] = { #endif #endif }; -STATIC MP_DEFINE_CONST_DICT(tca_module_globals, tca_module_globals_table); +static MP_DEFINE_CONST_DICT(tca_module_globals, tca_module_globals_table); // Define module object. const mp_obj_module_t tca_cmodule = { From 5f624a516a1602d3a1f869f2cabd2166a99945d9 Mon Sep 17 00:00:00 2001 From: ZodiusInfuser Date: Tue, 30 Apr 2024 16:32:25 +0100 Subject: [PATCH 2/8] Update patches --- firmware/micropython_nano_specs.patch | 11 ++++----- firmware/yukon_reset.patch | 32 +++++++++++++++++---------- 2 files changed, 26 insertions(+), 17 deletions(-) diff --git a/firmware/micropython_nano_specs.patch b/firmware/micropython_nano_specs.patch index 098c0bf..5ae938b 100644 --- a/firmware/micropython_nano_specs.patch +++ b/firmware/micropython_nano_specs.patch @@ -1,11 +1,11 @@ diff --git a/ports/rp2/CMakeLists.txt b/ports/rp2/CMakeLists.txt -index 094031c6852a..5f268414c08f 100644 +index fcc435b7b..efabcb3a3 100644 --- a/ports/rp2/CMakeLists.txt +++ b/ports/rp2/CMakeLists.txt -@@ -374,6 +374,15 @@ target_compile_options(${MICROPY_TARGET} PRIVATE - target_link_options(${MICROPY_TARGET} PRIVATE - -Wl,--defsym=__micropy_c_heap_size__=${MICROPY_C_HEAP_SIZE} +@@ -464,6 +464,16 @@ set_source_files_properties( + COMPILE_OPTIONS "-O2" ) + +# Do not include stack unwinding & exception handling for C++ user modules +target_compile_definitions(usermod INTERFACE PICO_CXX_ENABLE_EXCEPTIONS=0) +target_compile_options(usermod INTERFACE $<$: @@ -15,6 +15,7 @@ index 094031c6852a..5f268414c08f 100644 + -fno-use-cxa-atexit +>) +target_link_options(usermod INTERFACE -specs=nano.specs) - ++ set_source_files_properties( ${PICO_SDK_PATH}/src/rp2_common/pico_double/double_math.c + ${PICO_SDK_PATH}/src/rp2_common/pico_float/float_math.c diff --git a/firmware/yukon_reset.patch b/firmware/yukon_reset.patch index 17a1178..77c7aae 100644 --- a/firmware/yukon_reset.patch +++ b/firmware/yukon_reset.patch @@ -1,8 +1,8 @@ diff --git a/ports/rp2/CMakeLists.txt b/ports/rp2/CMakeLists.txt -index 87bc91b82..bf736ff91 100644 +index 1eaefcfb9..677a5e0e6 100644 --- a/ports/rp2/CMakeLists.txt +++ b/ports/rp2/CMakeLists.txt -@@ -281,6 +281,25 @@ target_include_directories(${MICROPY_TARGET} PRIVATE +@@ -322,6 +322,25 @@ target_include_directories(${MICROPY_TARGET} PRIVATE ${MICROPY_DIR}/shared/tinyusb/ ) @@ -28,7 +28,7 @@ index 87bc91b82..bf736ff91 100644 if (MICROPY_PY_NETWORK_CYW43) string(CONCAT GIT_SUBMODULES "${GIT_SUBMODULES} " lib/cyw43-driver) if((NOT (${ECHO_SUBMODULES})) AND NOT EXISTS ${MICROPY_DIR}/lib/cyw43-driver/src/cyw43.h) -@@ -498,6 +527,11 @@ target_sources(${MICROPY_TARGET} PRIVATE +@@ -548,6 +577,11 @@ target_sources(${MICROPY_TARGET} PRIVATE ${GEN_PINS_HDR} ) @@ -39,12 +39,12 @@ index 87bc91b82..bf736ff91 100644 + # Generate pins add_custom_command( - OUTPUT ${GEN_PINS_HDR} ${GEN_PINS_SRC} ${GEN_PINS_QSTR} + OUTPUT ${GEN_PINS_HDR} ${GEN_PINS_SRC} diff --git a/ports/rp2/main.c b/ports/rp2/main.c -index bb5ecc68d..9890bf580 100644 +index ec58b70ae..8c0571fcc 100644 --- a/ports/rp2/main.c +++ b/ports/rp2/main.c -@@ -150,6 +150,7 @@ int main(int argc, char **argv) { +@@ -152,6 +152,7 @@ int main(int argc, char **argv) { // Hook for setting up anything that can wait until after other hardware features are initialised MICROPY_BOARD_EARLY_INIT(); @@ -52,25 +52,33 @@ index bb5ecc68d..9890bf580 100644 for (;;) { // Initialise MicroPython runtime. -@@ -182,25 +183,34 @@ int main(int argc, char **argv) { +@@ -185,30 +186,39 @@ 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 (run_main) { ++ // Execute user scripts. ++ int ret = pyexec_file_if_exists("boot.py"); + +- #if MICROPY_HW_ENABLE_USBDEV +- mp_usbd_init(); +- #endif ++ #if MICROPY_HW_ENABLE_USBDEV ++ mp_usbd_init(); ++ #endif + - if (ret & PYEXEC_FORCED_EXIT) { - goto soft_reset_exit; - } -- if (pyexec_mode_kind == PYEXEC_MODE_FRIENDLY_REPL) { +- if (pyexec_mode_kind == PYEXEC_MODE_FRIENDLY_REPL && ret != 0) { - 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) { ++ if (pyexec_mode_kind == PYEXEC_MODE_FRIENDLY_REPL && ret != 0) { + ret = pyexec_file_if_exists("main.py"); + if (ret & PYEXEC_FORCED_EXIT) { + run_main = !(ret & PYEXEC_SKIP_USER_CODE); From 649d99fefc166e2f8260e99b6615f58bc44fa53e Mon Sep 17 00:00:00 2001 From: ZodiusInfuser Date: Tue, 3 Sep 2024 16:57:34 +0100 Subject: [PATCH 3/8] Updates for latest micropython --- .github/workflows/micropython.yml | 4 ++-- .github/workflows/python-linting.yml | 6 +++--- firmware/yukon_reset.patch | 18 +++++++++--------- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/.github/workflows/micropython.yml b/.github/workflows/micropython.yml index 4b55351..76828df 100644 --- a/.github/workflows/micropython.yml +++ b/.github/workflows/micropython.yml @@ -7,8 +7,8 @@ on: types: [created] env: - MICROPYTHON_VERSION: ae6c33a1dda01d5b36b8f5c9e8e0bd3425ba796a - PIMORONI_PICO_VERSION: dd757171c0d54044e89f2fba5916522307892bad + MICROPYTHON_VERSION: 7234375200d5cc28ab5caa09d443c9bf99786368 + PIMORONI_PICO_VERSION: 49a5d4292586f5851978f6f4a2f6b3214fb379ce WORKFLOW_VERSION: v2 jobs: diff --git a/.github/workflows/python-linting.yml b/.github/workflows/python-linting.yml index 666641d..0f97d32 100644 --- a/.github/workflows/python-linting.yml +++ b/.github/workflows/python-linting.yml @@ -12,14 +12,14 @@ jobs: - uses: actions/checkout@v4 - name: Install Python Deps - run: python3 -m pip install ruff + run: python3 -m pip install flake8 - name: Lint Yukon Examples shell: bash run: | - python3 -m ruff --show-source --ignore E501 examples/ + python3 -m flake8 --show-source --ignore E501,E201,E241,E222,E116,E266 examples/ - name: Lint Yukon Python Libraries shell: bash run: | - python3 -m ruff --show-source --ignore E501 lib/ \ No newline at end of file + python3 -m flake8 --show-source --ignore E501,E201,E241,E222,E116,E266 lib/ \ No newline at end of file diff --git a/firmware/yukon_reset.patch b/firmware/yukon_reset.patch index 77c7aae..5f403cf 100644 --- a/firmware/yukon_reset.patch +++ b/firmware/yukon_reset.patch @@ -1,8 +1,8 @@ diff --git a/ports/rp2/CMakeLists.txt b/ports/rp2/CMakeLists.txt -index 1eaefcfb9..677a5e0e6 100644 +index 19c7178fc..4f98e904b 100644 --- a/ports/rp2/CMakeLists.txt +++ b/ports/rp2/CMakeLists.txt -@@ -322,6 +322,25 @@ target_include_directories(${MICROPY_TARGET} PRIVATE +@@ -335,6 +335,25 @@ target_include_directories(${MICROPY_TARGET} PRIVATE ${MICROPY_DIR}/shared/tinyusb/ ) @@ -28,7 +28,7 @@ index 1eaefcfb9..677a5e0e6 100644 if (MICROPY_PY_NETWORK_CYW43) string(CONCAT GIT_SUBMODULES "${GIT_SUBMODULES} " lib/cyw43-driver) if((NOT (${ECHO_SUBMODULES})) AND NOT EXISTS ${MICROPY_DIR}/lib/cyw43-driver/src/cyw43.h) -@@ -548,6 +577,11 @@ target_sources(${MICROPY_TARGET} PRIVATE +@@ -562,6 +591,11 @@ target_sources(${MICROPY_TARGET} PRIVATE ${GEN_PINS_HDR} ) @@ -41,10 +41,10 @@ index 1eaefcfb9..677a5e0e6 100644 add_custom_command( OUTPUT ${GEN_PINS_HDR} ${GEN_PINS_SRC} diff --git a/ports/rp2/main.c b/ports/rp2/main.c -index ec58b70ae..8c0571fcc 100644 +index 134e0edac..37498dd87 100644 --- a/ports/rp2/main.c +++ b/ports/rp2/main.c -@@ -152,6 +152,7 @@ int main(int argc, char **argv) { +@@ -158,6 +158,7 @@ int main(int argc, char **argv) { // Hook for setting up anything that can wait until after other hardware features are initialised MICROPY_BOARD_EARLY_INIT(); @@ -52,7 +52,7 @@ index ec58b70ae..8c0571fcc 100644 for (;;) { // Initialise MicroPython runtime. -@@ -185,30 +186,39 @@ int main(int argc, char **argv) { +@@ -191,30 +192,39 @@ int main(int argc, char **argv) { pyexec_frozen_module("_boot.py", false); #endif @@ -105,11 +105,11 @@ index ec58b70ae..8c0571fcc 100644 } } diff --git a/shared/runtime/pyexec.h b/shared/runtime/pyexec.h -index 64c5ef943..6a2cd8b8f 100644 +index 5779d3e09..eb92fbb04 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; +@@ -36,6 +36,7 @@ typedef enum { + extern pyexec_mode_kind_t pyexec_mode_kind; #define PYEXEC_FORCED_EXIT (0x100) +#define PYEXEC_SKIP_USER_CODE (0x200) From 34dc7c7e6124de936fd33669976b326379a9f06d Mon Sep 17 00:00:00 2001 From: ZodiusInfuser Date: Thu, 5 Sep 2024 11:52:37 +0100 Subject: [PATCH 4/8] Update patch to remove redundant code --- firmware/yukon_reset.patch | 88 -------------------------------------- 1 file changed, 88 deletions(-) diff --git a/firmware/yukon_reset.patch b/firmware/yukon_reset.patch index 5f403cf..9cd91ec 100644 --- a/firmware/yukon_reset.patch +++ b/firmware/yukon_reset.patch @@ -28,91 +28,3 @@ index 19c7178fc..4f98e904b 100644 if (MICROPY_PY_NETWORK_CYW43) string(CONCAT GIT_SUBMODULES "${GIT_SUBMODULES} " lib/cyw43-driver) if((NOT (${ECHO_SUBMODULES})) AND NOT EXISTS ${MICROPY_DIR}/lib/cyw43-driver/src/cyw43.h) -@@ -562,6 +591,11 @@ target_sources(${MICROPY_TARGET} PRIVATE - ${GEN_PINS_HDR} - ) - -+# Temporary hack to get build finding correct CSV file -+pico_find_in_paths(GEN_PINS_BOARD_CSV PICO_BOARD_HEADER_DIRS pins.csv) -+message(WARNING "${GEN_PINS_BOARD_CSV}") -+set(GEN_PINS_CSV_ARG --board "${GEN_PINS_BOARD_CSV}") -+ - # Generate pins - add_custom_command( - OUTPUT ${GEN_PINS_HDR} ${GEN_PINS_SRC} -diff --git a/ports/rp2/main.c b/ports/rp2/main.c -index 134e0edac..37498dd87 100644 ---- a/ports/rp2/main.c -+++ b/ports/rp2/main.c -@@ -158,6 +158,7 @@ int main(int argc, char **argv) { - // Hook for setting up anything that can wait until after other hardware features are initialised - MICROPY_BOARD_EARLY_INIT(); - -+ bool run_main = true; - for (;;) { - - // Initialise MicroPython runtime. -@@ -191,30 +192,39 @@ 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 (run_main) { -+ // Execute user scripts. -+ int ret = pyexec_file_if_exists("boot.py"); - -- #if MICROPY_HW_ENABLE_USBDEV -- mp_usbd_init(); -- #endif -+ #if MICROPY_HW_ENABLE_USBDEV -+ mp_usbd_init(); -+ #endif - -- 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) { -+ run_main = !(ret & PYEXEC_SKIP_USER_CODE); - 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) { -+ 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; - } - } -diff --git a/shared/runtime/pyexec.h b/shared/runtime/pyexec.h -index 5779d3e09..eb92fbb04 100644 ---- a/shared/runtime/pyexec.h -+++ b/shared/runtime/pyexec.h -@@ -36,6 +36,7 @@ typedef enum { - extern pyexec_mode_kind_t pyexec_mode_kind; - - #define PYEXEC_FORCED_EXIT (0x100) -+#define PYEXEC_SKIP_USER_CODE (0x200) - - int pyexec_raw_repl(void); - int pyexec_friendly_repl(void); From 94570ce861c083beb0f1962e65d6730fbd023e26 Mon Sep 17 00:00:00 2001 From: ZodiusInfuser Date: Thu, 5 Sep 2024 11:53:21 +0100 Subject: [PATCH 5/8] Renamed patch to reflect its new use --- .github/workflows/micropython.yml | 4 ++-- firmware/{yukon_reset.patch => yukon_expander.patch} | 0 2 files changed, 2 insertions(+), 2 deletions(-) rename firmware/{yukon_reset.patch => yukon_expander.patch} (100%) diff --git a/.github/workflows/micropython.yml b/.github/workflows/micropython.yml index 76828df..5baea99 100644 --- a/.github/workflows/micropython.yml +++ b/.github/workflows/micropython.yml @@ -123,10 +123,10 @@ jobs: working-directory: micropython run: git apply "${{env.FIRMWARE_DIR}}/micropython_nano_specs.patch" - - name: "HACK: Yukon Reset Patch" + - name: "HACK: Yukon Expander Patch" shell: bash working-directory: micropython - run: git apply "${{env.FIRMWARE_DIR}}/yukon_reset.patch" + run: git apply "${{env.FIRMWARE_DIR}}/yukon_expander.patch" # Install apt packages - name: Install CCache & Compiler diff --git a/firmware/yukon_reset.patch b/firmware/yukon_expander.patch similarity index 100% rename from firmware/yukon_reset.patch rename to firmware/yukon_expander.patch From de5a54b72ba6871db1b87431e09e1aa0de94af4f Mon Sep 17 00:00:00 2001 From: ZodiusInfuser Date: Thu, 5 Sep 2024 13:10:24 +0100 Subject: [PATCH 6/8] Update init hooks --- .github/workflows/micropython.yml | 2 +- firmware/PIMORONI_YUKON/mpconfigboard.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/micropython.yml b/.github/workflows/micropython.yml index 5baea99..a4e814d 100644 --- a/.github/workflows/micropython.yml +++ b/.github/workflows/micropython.yml @@ -7,7 +7,7 @@ on: types: [created] env: - MICROPYTHON_VERSION: 7234375200d5cc28ab5caa09d443c9bf99786368 + MICROPYTHON_VERSION: d131d20033858e91557577a7de71e09f2c56eab5 PIMORONI_PICO_VERSION: 49a5d4292586f5851978f6f4a2f6b3214fb379ce WORKFLOW_VERSION: v2 diff --git a/firmware/PIMORONI_YUKON/mpconfigboard.h b/firmware/PIMORONI_YUKON/mpconfigboard.h index 0d02b72..5f46555 100644 --- a/firmware/PIMORONI_YUKON/mpconfigboard.h +++ b/firmware/PIMORONI_YUKON/mpconfigboard.h @@ -21,5 +21,5 @@ #define MICROPY_BOARD_EARLY_INIT board_init void board_init(void); -#define MICROPY_BOARD_EARLY_RESET board_reset +#define MICROPY_BOARD_START_SOFT_RESET board_reset void board_reset(void); \ No newline at end of file From b6d8234b91d8b5c08a89f4f587c7be1db19440d8 Mon Sep 17 00:00:00 2001 From: ZodiusInfuser Date: Thu, 26 Sep 2024 17:03:24 +0100 Subject: [PATCH 7/8] Update CI to latest --- .github/workflows/micropython.yml | 41 +++++++++++++++++++++---------- 1 file changed, 28 insertions(+), 13 deletions(-) diff --git a/.github/workflows/micropython.yml b/.github/workflows/micropython.yml index a4e814d..44069a3 100644 --- a/.github/workflows/micropython.yml +++ b/.github/workflows/micropython.yml @@ -7,7 +7,7 @@ on: types: [created] env: - MICROPYTHON_VERSION: d131d20033858e91557577a7de71e09f2c56eab5 + MICROPYTHON_VERSION: 17d82344581ad3a76033fae54c5d3304e17f185f PIMORONI_PICO_VERSION: 49a5d4292586f5851978f6f4a2f6b3214fb379ce WORKFLOW_VERSION: v2 @@ -30,7 +30,7 @@ jobs: if: steps.cache.outputs.cache-hit != 'true' uses: actions/checkout@v4 with: - repository: pimoroni/micropython + repository: micropython/micropython ref: ${{env.MICROPYTHON_VERSION}} submodules: false # MicroPython submodules are hideously broken path: micropython @@ -41,9 +41,12 @@ 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' @@ -61,9 +64,6 @@ jobs: - name: Yukon shortname: yukon board: PIMORONI_YUKON - # 0x10000000 + (16*1024*1024) - (15*1024*1024) - dir2uf2_fs_start: 269484032 - dir2uf2_fs_size: 15728640 env: RELEASE_FILE: pimoroni-${{matrix.shortname}}-${{github.event.release.tag_name || github.sha}}-micropython @@ -104,11 +104,18 @@ jobs: submodules: true path: pimoroni-pico + - name: "Py_Decl: Checkout py_decl" + uses: actions/checkout@v4 + with: + repository: gadgetoid/py_decl + ref: v0.0.1 + path: py_decl + # Check out dir2u2f - uses: actions/checkout@v4 with: repository: gadgetoid/dir2uf2 - ref: v0.0.1 + ref: v0.0.6 path: dir2uf2 # HACK: Patch startup overclock into Pico SDK @@ -128,11 +135,14 @@ jobs: working-directory: micropython run: git apply "${{env.FIRMWARE_DIR}}/yukon_expander.patch" - # Install apt packages - - name: Install CCache & Compiler - shell: bash - run: - sudo apt update && sudo apt install ccache gcc-arm-none-eabi + - name: Install Arm GNU Toolchain (arm-none-eabi-gcc) + uses: carlosperate/arm-none-eabi-gcc-action@v1 + with: + release: '9-2020-q2' + + - name: Install CCache + run: | + sudo apt update && sudo apt install ccache # Build firmware - name: Configure MicroPython @@ -155,11 +165,16 @@ jobs: run: | cp firmware.uf2 ${{env.RELEASE_FILE}}.uf2 + - name: "Py_Decl: Verify UF2" + shell: bash + run: | + python3 py_decl/py_decl.py --to-json --verify micropython/ports/rp2/build/${{env.RELEASE_FILE}}.uf2 + - name: Append Filesystem shell: bash run: | - python3 -m pip install littlefs-python==0.4.0 - ./dir2uf2/dir2uf2 --verbose --fs-start ${{matrix.dir2uf2_fs_start}} --fs-size ${{matrix.dir2uf2_fs_size}} --append-to micropython/ports/rp2/build/${{env.RELEASE_FILE}}.uf2 --manifest ${{env.BOARD_DIR}}/uf2-manifest.txt --filename ${{env.FILESYSTEM_SUFFIX}}.uf2 ${{env.FILESYSTEM_DIR}}/ + python3 -m pip install littlefs-python==0.12.0 + ./dir2uf2/dir2uf2 --fs-compact --append-to micropython/ports/rp2/build/${{env.RELEASE_FILE}}.uf2 --manifest ${{env.BOARD_DIR}}/uf2-manifest.txt --filename ${{env.FILESYSTEM_SUFFIX}}.uf2 ${{env.FILESYSTEM_DIR}}/ - name: Store .uf2 as artifact uses: actions/upload-artifact@v4 From f25f1970028fa31dc66e28e0f0b79543fc5f5394 Mon Sep 17 00:00:00 2001 From: ZodiusInfuser Date: Thu, 26 Sep 2024 17:16:41 +0100 Subject: [PATCH 8/8] Bump version number --- lib/pimoroni_yukon/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/pimoroni_yukon/__init__.py b/lib/pimoroni_yukon/__init__.py index 2770b23..1e41bdb 100644 --- a/lib/pimoroni_yukon/__init__.py +++ b/lib/pimoroni_yukon/__init__.py @@ -15,7 +15,7 @@ from ucollections import OrderedDict, namedtuple -YUKON_VERSION = "1.0.1" +YUKON_VERSION = "1.0.2" Slot = namedtuple("Slot", ("ID", "FAST1",