summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlessandro Gatti <a.gatti@frob.it>2025-03-25 22:43:23 +0100
committerAlessandro Gatti <a.gatti@frob.it>2025-05-14 06:26:31 +0200
commit883dc41d465a6a652b607b7982d8eb6be39fa7f4 (patch)
tree42b5ce4455120ea9f4037292d209ee3f38bf4068
parent116d0d494589e470b4003fcecd18162c9eed7e9b (diff)
esp32/main: Make the entry point function name configurable.
This commit introduces a new port configuration entry allowing the entry point function name to be changed, from "app_main" to a custom name. This is needed when MicroPython is embedded as an ESP-IDF component, since the "app_main" symbol is already provided elsewhere, making compilation not possible. Marking MicroPython's symbol as weak would make it compile and make it possible to create and start the MicroPython task anyway with the right FreeRTOS task creation incantation, but it is probably easier to just rename the initialisation function into something else that can be accessed from outside. When MicroPython is embedded as an ESP-IDF component, the MICROPY_ESP_IDF_ENTRY definition can be set to indicate the new entry point function name. The new function name prototype should still be defined in external code to let linking succeed. Also, the NLR failure callback is marked as weak to give the chance of handling such error in a more controlled fashion rather than trigger an unconditional board restart. Signed-off-by: Alessandro Gatti <a.gatti@frob.it>
-rw-r--r--ports/esp32/main.c4
-rw-r--r--ports/esp32/mpconfigport.h5
2 files changed, 7 insertions, 2 deletions
diff --git a/ports/esp32/main.c b/ports/esp32/main.c
index 4f0c27ee0..b8f49a33b 100644
--- a/ports/esp32/main.c
+++ b/ports/esp32/main.c
@@ -216,7 +216,7 @@ void boardctrl_startup(void) {
}
}
-void app_main(void) {
+void MICROPY_ESP_IDF_ENTRY(void) {
// Hook for a board to run code at start up.
// This defaults to initialising NVS.
MICROPY_BOARD_STARTUP();
@@ -225,7 +225,7 @@ void app_main(void) {
xTaskCreatePinnedToCore(mp_task, "mp_task", MICROPY_TASK_STACK_SIZE / sizeof(StackType_t), NULL, MP_TASK_PRIORITY, &mp_main_task_handle, MP_TASK_COREID);
}
-void nlr_jump_fail(void *val) {
+MP_WEAK void nlr_jump_fail(void *val) {
printf("NLR jump failed, val=%p\n", val);
esp_restart();
}
diff --git a/ports/esp32/mpconfigport.h b/ports/esp32/mpconfigport.h
index b5b7d63a5..7c2600957 100644
--- a/ports/esp32/mpconfigport.h
+++ b/ports/esp32/mpconfigport.h
@@ -391,3 +391,8 @@ void boardctrl_startup(void);
#ifndef MICROPY_PY_STRING_TX_GIL_THRESHOLD
#define MICROPY_PY_STRING_TX_GIL_THRESHOLD (20)
#endif
+
+// Code can override this to provide a custom ESP-IDF entry point.
+#ifndef MICROPY_ESP_IDF_ENTRY
+#define MICROPY_ESP_IDF_ENTRY app_main
+#endif