ESP32的启动过程分为三步,加载bootloader,加载映像等,执行main_task()。
omponents/esp32/cpu_start.c
static void main_task(void* args)
{
// Now that the application is about to start, disable boot watchdogs
REG_CLR_BIT(TIMG_WDTCONFIG0_REG(0), TIMG_WDT_FLASHBOOT_MOD_EN_S);
REG_CLR_BIT(RTC_CNTL_WDTCONFIG0_REG, RTC_CNTL_WDT_FLASHBOOT_MOD_EN);
#if !CONFIG_FREERTOS_UNICORE
// Wait for FreeRTOS initialization to finish on APP CPU, before replacing its startup stack
while (port_xSchedulerRunning[1] == 0) {
;
}
#endif
//Enable allocation in region where the startup stacks were located.
heap_caps_enable_nonos_stack_heaps();
app_main();
vTaskDelete(NULL);
}
这其中的app_main()就是我们二次开发的入口。在app_main执行后,vTaskDelet函数就将这个任务删除了。
整个ESP-DIF是基于Freertos的,在app_main()中可以创建任务等。