Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to latest version of MicroPython #16

Merged
merged 8 commits into from
Sep 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 31 additions & 16 deletions .github/workflows/micropython.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ on:
types: [created]

env:
MICROPYTHON_VERSION: b88262ce96c3433a02b2c8d984ba01e071b60c1f
PIMORONI_PICO_VERSION: 7678ba5da966c3d8b7238e2b2f4e604ffe377dd6
MICROPYTHON_VERSION: 17d82344581ad3a76033fae54c5d3304e17f185f
PIMORONI_PICO_VERSION: 49a5d4292586f5851978f6f4a2f6b3214fb379ce
WORKFLOW_VERSION: v2

jobs:
Expand All @@ -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
Expand All @@ -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'
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -123,16 +130,19 @@ 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
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
Expand All @@ -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
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/python-linting.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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/
python3 -m flake8 --show-source --ignore E501,E201,E241,E222,E116,E266 lib/
2 changes: 1 addition & 1 deletion firmware/PIMORONI_YUKON/mpconfigboard.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
2 changes: 1 addition & 1 deletion firmware/drivers/tca9555/machine_pin_tca9555.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
11 changes: 6 additions & 5 deletions firmware/micropython_nano_specs.patch
Original file line number Diff line number Diff line change
@@ -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 $<$<COMPILE_LANGUAGE:CXX>:
Expand All @@ -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
53 changes: 27 additions & 26 deletions firmware/modules/tca9555/tca.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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);
}
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -92,79 +93,79 @@ 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);
}

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);
}

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);
}

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);
}

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);
}

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);
}

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);
}

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

Expand All @@ -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 },
Expand All @@ -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 = {
Expand Down
30 changes: 30 additions & 0 deletions firmware/yukon_expander.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
diff --git a/ports/rp2/CMakeLists.txt b/ports/rp2/CMakeLists.txt
index 19c7178fc..4f98e904b 100644
--- a/ports/rp2/CMakeLists.txt
+++ b/ports/rp2/CMakeLists.txt
@@ -335,6 +335,25 @@ target_include_directories(${MICROPY_TARGET} PRIVATE
${MICROPY_DIR}/shared/tinyusb/
)

+if (MICROPY_TCA9555_DIR)
+ target_compile_definitions(${MICROPY_TARGET} PRIVATE
+ MICROPY_PY_TCA9555=1
+ MICROPY_HW_PIN_EXT_COUNT=32
+ )
+
+ list(APPEND MICROPY_SOURCE_PORT
+ ${MICROPY_TCA9555_DIR}/machine_pin_tca9555.c
+ )
+
+ list(APPEND MICROPY_SOURCE_DRIVERS
+ ${MICROPY_TCA9555_DIR}/tca9555.c
+ )
+
+ target_include_directories(${MICROPY_TARGET} PRIVATE
+ ${MICROPY_TCA9555_DIR}
+ )
+endif()
+
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)
Loading