summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDamien George <damien@micropython.org>2021-09-22 00:00:26 +1000
committerDamien George <damien@micropython.org>2021-09-24 12:23:14 +1000
commitf046b50ca591e16f78ffaae3c45a19afaeba839b (patch)
tree6768809b885d6b5118e95cf84cbe392d1b4878eb
parent4fdf795efa4eca3a9f8166e33b991a762569ae20 (diff)
esp32/main: Add option for a board to hook code into startup sequence.
To do this the board must define MICROPY_BOARD_STARTUP, set MICROPY_SOURCE_BOARD then define the new start-up code. For example, in mpconfigboard.h: #define MICROPY_BOARD_STARTUP board_startup void board_startup(void); in mpconfigboard.cmake: set(MICROPY_SOURCE_BOARD ${MICROPY_BOARD_DIR}/board.c ) and in a new board.c file in the board directory: #include "py/mpconfig.h" void board_startup(void) { boardctrl_startup(); // extra custom startup } This follows stm32's boardctrl facilities. Signed-off-by: Damien George <damien@micropython.org>
-rw-r--r--ports/esp32/main.c10
-rw-r--r--ports/esp32/main/CMakeLists.txt2
-rw-r--r--ports/esp32/mpconfigport.h6
3 files changed, 17 insertions, 1 deletions
diff --git a/ports/esp32/main.c b/ports/esp32/main.c
index 2ba613668..ca0ab1488 100644
--- a/ports/esp32/main.c
+++ b/ports/esp32/main.c
@@ -202,12 +202,20 @@ soft_reset_exit:
goto soft_reset;
}
-void app_main(void) {
+void boardctrl_startup(void) {
esp_err_t ret = nvs_flash_init();
if (ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND) {
nvs_flash_erase();
nvs_flash_init();
}
+}
+
+void app_main(void) {
+ // Hook for a board to run code at start up.
+ // This defaults to initialising NVS.
+ MICROPY_BOARD_STARTUP();
+
+ // Create and transfer control to the MicroPython task.
xTaskCreatePinnedToCore(mp_task, "mp_task", MP_TASK_STACK_SIZE / sizeof(StackType_t), NULL, MP_TASK_PRIORITY, &mp_main_task_handle, MP_TASK_COREID);
}
diff --git a/ports/esp32/main/CMakeLists.txt b/ports/esp32/main/CMakeLists.txt
index 75e123f4e..18d7dc7fa 100644
--- a/ports/esp32/main/CMakeLists.txt
+++ b/ports/esp32/main/CMakeLists.txt
@@ -89,6 +89,7 @@ set(MICROPY_SOURCE_QSTR
${MICROPY_SOURCE_SHARED}
${MICROPY_SOURCE_LIB}
${MICROPY_SOURCE_PORT}
+ ${MICROPY_SOURCE_BOARD}
)
set(IDF_COMPONENTS
@@ -156,6 +157,7 @@ idf_component_register(
${MICROPY_SOURCE_LIB}
${MICROPY_SOURCE_DRIVERS}
${MICROPY_SOURCE_PORT}
+ ${MICROPY_SOURCE_BOARD}
INCLUDE_DIRS
${MICROPY_INC_CORE}
${MICROPY_INC_USERMOD}
diff --git a/ports/esp32/mpconfigport.h b/ports/esp32/mpconfigport.h
index 6a48ce502..5affbb069 100644
--- a/ports/esp32/mpconfigport.h
+++ b/ports/esp32/mpconfigport.h
@@ -308,3 +308,9 @@ typedef long mp_off_t;
#ifndef MICROPY_HW_ENABLE_MDNS_RESPONDER
#define MICROPY_HW_ENABLE_MDNS_RESPONDER (1)
#endif
+
+#ifndef MICROPY_BOARD_STARTUP
+#define MICROPY_BOARD_STARTUP boardctrl_startup
+#endif
+
+void boardctrl_startup(void);