diff options
| author | ZodiusInfuser <christopher.parrott2@gmail.com> | 2024-09-05 12:53:16 +0100 |
|---|---|---|
| committer | Damien George <damien@micropython.org> | 2024-09-19 12:54:20 +1000 |
| commit | 5dfd3ecd8b1c99ae08ce082102606739bde57852 (patch) | |
| tree | 013134e04f7b55a0c09277297e9969d401a26b1f | |
| parent | fb069f9d0623e0794eb1da30148cbc9ca32d3d50 (diff) | |
rp2: Add board-level hooks to main, and MICROPY_SOURCE_BOARD cmake var.
Signed-off-by: Christopher Parrott <chris@pimoroni.com>
| -rw-r--r-- | ports/rp2/CMakeLists.txt | 2 | ||||
| -rw-r--r-- | ports/rp2/main.c | 13 | ||||
| -rw-r--r-- | ports/rp2/mpconfigport.h | 16 |
3 files changed, 31 insertions, 0 deletions
diff --git a/ports/rp2/CMakeLists.txt b/ports/rp2/CMakeLists.txt index 904925ae3..19c7178fc 100644 --- a/ports/rp2/CMakeLists.txt +++ b/ports/rp2/CMakeLists.txt @@ -425,6 +425,7 @@ endif() list(APPEND MICROPY_SOURCE_QSTR ${MICROPY_SOURCE_EXTMOD} ${MICROPY_SOURCE_USERMOD} + ${MICROPY_SOURCE_BOARD} ) # Define mpy-cross flags @@ -443,6 +444,7 @@ target_sources(${MICROPY_TARGET} PRIVATE ${MICROPY_SOURCE_LIB} ${MICROPY_SOURCE_DRIVERS} ${MICROPY_SOURCE_PORT} + ${MICROPY_SOURCE_BOARD} ) target_link_libraries(${MICROPY_TARGET} micropy_lib_mbedtls) diff --git a/ports/rp2/main.c b/ports/rp2/main.c index 98417e8da..7fb4a6486 100644 --- a/ports/rp2/main.c +++ b/ports/rp2/main.c @@ -83,6 +83,9 @@ int main(int argc, char **argv) { // Set the MCU frequency and as a side effect the peripheral clock to 48 MHz. set_sys_clock_khz(125000, false); + // Hook for setting up anything that needs to be super early in the bootup process. + MICROPY_BOARD_STARTUP(); + #if MICROPY_HW_ENABLE_UART_REPL bi_decl(bi_program_feature("UART REPL")) setup_default_uart(); @@ -152,6 +155,9 @@ int main(int argc, char **argv) { } #endif + // Hook for setting up anything that can wait until after other hardware features are initialised. + MICROPY_BOARD_EARLY_INIT(); + for (;;) { // Initialise MicroPython runtime. @@ -213,6 +219,10 @@ int main(int argc, char **argv) { soft_reset_exit: mp_printf(MP_PYTHON_PRINTER, "MPY: soft reboot\n"); + + // Hook for resetting anything immediately following a soft reset command. + MICROPY_BOARD_START_SOFT_RESET(); + #if MICROPY_PY_NETWORK mod_network_deinit(); #endif @@ -233,6 +243,9 @@ int main(int argc, char **argv) { mp_usbd_deinit(); #endif + // Hook for resetting anything right at the end of a soft reset command. + MICROPY_BOARD_END_SOFT_RESET(); + gc_sweep_all(); mp_deinit(); #if MICROPY_HW_ENABLE_UART_REPL diff --git a/ports/rp2/mpconfigport.h b/ports/rp2/mpconfigport.h index 49acafe23..b34b4fc09 100644 --- a/ports/rp2/mpconfigport.h +++ b/ports/rp2/mpconfigport.h @@ -283,3 +283,19 @@ extern void lwip_lock_release(void); #define MICROPY_PY_BLUETOOTH_ENTER uint32_t atomic_state = 0; #define MICROPY_PY_BLUETOOTH_EXIT (void)atomic_state; #endif + +#ifndef MICROPY_BOARD_STARTUP +#define MICROPY_BOARD_STARTUP() +#endif + +#ifndef MICROPY_BOARD_EARLY_INIT +#define MICROPY_BOARD_EARLY_INIT() +#endif + +#ifndef MICROPY_BOARD_START_SOFT_RESET +#define MICROPY_BOARD_START_SOFT_RESET() +#endif + +#ifndef MICROPY_BOARD_END_SOFT_RESET +#define MICROPY_BOARD_END_SOFT_RESET() +#endif |
