rp2: Add board-level hooks to main, and MICROPY_SOURCE_BOARD cmake var.

Signed-off-by: Christopher Parrott <chris@pimoroni.com>
This commit is contained in:
ZodiusInfuser
2024-09-05 12:53:16 +01:00
committed by Damien George
parent fb069f9d06
commit 5dfd3ecd8b
3 changed files with 31 additions and 0 deletions

View File

@@ -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)

View File

@@ -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

View File

@@ -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