Skip to content

Commit 883dc41

Browse files
committed
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 <[email protected]>
1 parent 116d0d4 commit 883dc41

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

ports/esp32/main.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ void boardctrl_startup(void) {
216216
}
217217
}
218218

219-
void app_main(void) {
219+
void MICROPY_ESP_IDF_ENTRY(void) {
220220
// Hook for a board to run code at start up.
221221
// This defaults to initialising NVS.
222222
MICROPY_BOARD_STARTUP();
@@ -225,7 +225,7 @@ void app_main(void) {
225225
xTaskCreatePinnedToCore(mp_task, "mp_task", MICROPY_TASK_STACK_SIZE / sizeof(StackType_t), NULL, MP_TASK_PRIORITY, &mp_main_task_handle, MP_TASK_COREID);
226226
}
227227

228-
void nlr_jump_fail(void *val) {
228+
MP_WEAK void nlr_jump_fail(void *val) {
229229
printf("NLR jump failed, val=%p\n", val);
230230
esp_restart();
231231
}

ports/esp32/mpconfigport.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -391,3 +391,8 @@ void boardctrl_startup(void);
391391
#ifndef MICROPY_PY_STRING_TX_GIL_THRESHOLD
392392
#define MICROPY_PY_STRING_TX_GIL_THRESHOLD (20)
393393
#endif
394+
395+
// Code can override this to provide a custom ESP-IDF entry point.
396+
#ifndef MICROPY_ESP_IDF_ENTRY
397+
#define MICROPY_ESP_IDF_ENTRY app_main
398+
#endif

0 commit comments

Comments
 (0)