From 921dd94676815f794190484038ccacf001e68ea0 Mon Sep 17 00:00:00 2001 From: iabdalkader Date: Wed, 6 Jan 2021 20:19:29 +0200 Subject: [PATCH] nrf/main: Add startup and early-init board hook macros. Following stm32 for naming and location of the hooks. Also allow a board to provide custom .c files to implement code for these hooks. --- ports/nrf/Makefile | 1 + ports/nrf/main.c | 5 +++++ ports/nrf/mpconfigport.h | 8 ++++++++ 3 files changed, 14 insertions(+) diff --git a/ports/nrf/Makefile b/ports/nrf/Makefile index c32e09d2c9..55cce1906d 100644 --- a/ports/nrf/Makefile +++ b/ports/nrf/Makefile @@ -274,6 +274,7 @@ SRC_C += \ drivers/ticker.c \ drivers/bluetooth/ble_drv.c \ drivers/bluetooth/ble_uart.c \ + $(wildcard $(BOARD_DIR)/*.c) \ ifeq ($(MCU_SUB_VARIANT), nrf52840) diff --git a/ports/nrf/main.c b/ports/nrf/main.c index 2ec16194cb..091aa73f45 100644 --- a/ports/nrf/main.c +++ b/ports/nrf/main.c @@ -107,9 +107,14 @@ extern uint32_t _heap_start; extern uint32_t _heap_end; int main(int argc, char **argv) { + // Hook for a board to run code at start up, for example check if a + // bootloader should be entered instead of the main application. + MICROPY_BOARD_STARTUP(); + MICROPY_BOARD_EARLY_INIT(); soft_reset: + #if MICROPY_PY_TIME_TICKS rtc1_init_time_ticks(); #endif diff --git a/ports/nrf/mpconfigport.h b/ports/nrf/mpconfigport.h index 29bdd3f80c..04bd5b4c26 100644 --- a/ports/nrf/mpconfigport.h +++ b/ports/nrf/mpconfigport.h @@ -366,3 +366,11 @@ extern const struct _mp_obj_module_t music_module; #ifndef MP_NEED_LOG2 #define MP_NEED_LOG2 (1) #endif + +#ifndef MICROPY_BOARD_STARTUP +#define MICROPY_BOARD_STARTUP() +#endif + +#ifndef MICROPY_BOARD_EARLY_INIT +#define MICROPY_BOARD_EARLY_INIT() +#endif