From 62aaec630c2d60ce108f3503c0e3841b9c720998 Mon Sep 17 00:00:00 2001 From: Ivan Grokhotkov Date: Mon, 26 Sep 2016 12:29:00 +0800 Subject: [PATCH] components/esp32: remove "_user" part from entry points, weaken start_cpu0/1 With this change applications can override very early part of startup procedure by implementing "start_cpu0" and "start_cpu1" functions. --- components/esp32/cpu_start.c | 57 +++++++++++++++-------------- components/esp32/ld/esp32.common.ld | 2 +- 2 files changed, 31 insertions(+), 28 deletions(-) diff --git a/components/esp32/cpu_start.c b/components/esp32/cpu_start.c index 5566d978a0..76a5e6a1c5 100644 --- a/components/esp32/cpu_start.c +++ b/components/esp32/cpu_start.c @@ -43,9 +43,13 @@ #include "esp_ipc.h" #include "esp_log.h" -static void IRAM_ATTR user_start_cpu0(void); -static void IRAM_ATTR call_user_start_cpu1(); -static void IRAM_ATTR user_start_cpu1(void); +void start_cpu0(void) __attribute__((weak, alias("start_cpu0_default"))); +void start_cpu1(void) __attribute__((weak, alias("start_cpu0_default"))); +void start_cpu0_default(void) IRAM_ATTR; +void start_cpu1_default(void) IRAM_ATTR; +static void IRAM_ATTR call_start_cpu1(); +static void do_global_ctors(void); +static void main_task(void* args); extern void ets_setup_syscalls(void); extern int main(void); @@ -64,7 +68,7 @@ static bool app_cpu_started = false; * and the app CPU is in reset. We do have a stack, so we can do the initialization in C. */ -void IRAM_ATTR call_user_start_cpu0() +void IRAM_ATTR call_start_cpu0() { //Kill wdt REG_CLR_BIT(RTC_CNTL_WDTCONFIG0_REG, RTC_CNTL_WDT_FLASHBOOT_MOD_EN); @@ -88,13 +92,13 @@ void IRAM_ATTR call_user_start_cpu0() ESP_EARLY_LOGI(TAG, "Pro cpu up."); #ifndef CONFIG_FREERTOS_UNICORE - ESP_EARLY_LOGI(TAG, "Starting app cpu, entry point is %p", call_user_start_cpu1); + ESP_EARLY_LOGI(TAG, "Starting app cpu, entry point is %p", call_start_cpu1); SET_PERI_REG_MASK(DPORT_APPCPU_CTRL_B_REG, DPORT_APPCPU_CLKGATE_EN); CLEAR_PERI_REG_MASK(DPORT_APPCPU_CTRL_C_REG, DPORT_APPCPU_RUNSTALL); SET_PERI_REG_MASK(DPORT_APPCPU_CTRL_A_REG, DPORT_APPCPU_RESETTING); CLEAR_PERI_REG_MASK(DPORT_APPCPU_CTRL_A_REG, DPORT_APPCPU_RESETTING); - ets_set_appcpu_boot_addr((uint32_t)call_user_start_cpu1); + ets_set_appcpu_boot_addr((uint32_t)call_start_cpu1); while (!app_cpu_started) { ets_delay_us(100); @@ -104,11 +108,10 @@ void IRAM_ATTR call_user_start_cpu0() CLEAR_PERI_REG_MASK(DPORT_APPCPU_CTRL_B_REG, DPORT_APPCPU_CLKGATE_EN); #endif ESP_EARLY_LOGI(TAG, "Pro cpu start user code"); - user_start_cpu0(); + start_cpu0(); } - -void IRAM_ATTR call_user_start_cpu1() +void IRAM_ATTR call_start_cpu1() { asm volatile (\ "wsr %0, vecbase\n" \ @@ -118,10 +121,25 @@ void IRAM_ATTR call_user_start_cpu1() ESP_EARLY_LOGI(TAG, "App cpu up."); app_cpu_started = 1; - user_start_cpu1(); + start_cpu1(); +} + +void start_cpu0_default(void) +{ + esp_set_cpu_freq(); // set CPU frequency configured in menuconfig + uart_div_modify(0, (APB_CLK_FREQ << 4) / 115200); + ets_setup_syscalls(); + do_global_ctors(); + esp_ipc_init(); + spi_flash_init(); + xTaskCreatePinnedToCore(&main_task, "main", + ESP_TASK_MAIN_STACK, NULL, + ESP_TASK_MAIN_PRIO, NULL, 0); + ESP_LOGI(TAG, "Starting scheduler on PRO CPU."); + vTaskStartScheduler(); } -void IRAM_ATTR user_start_cpu1(void) +void start_cpu1_default(void) { // Wait for FreeRTOS initialization to finish on PRO CPU while (port_xSchedulerRunning[0] == 0) { @@ -139,24 +157,9 @@ static void do_global_ctors(void) } } -static void mainTask(void* args) +static void main_task(void* args) { main(); vTaskDelete(NULL); } -void user_start_cpu0(void) -{ - esp_set_cpu_freq(); // set CPU frequency configured in menuconfig - uart_div_modify(0, (APB_CLK_FREQ << 4) / 115200); - ets_setup_syscalls(); - do_global_ctors(); - esp_ipc_init(); - spi_flash_init(); - xTaskCreatePinnedToCore(&mainTask, "mainTask", - ESP_TASK_MAIN_STACK, NULL, - ESP_TASK_MAIN_PRIO, NULL, 0); - ESP_LOGI(TAG, "Starting scheduler on PRO CPU."); - vTaskStartScheduler(); -} - diff --git a/components/esp32/ld/esp32.common.ld b/components/esp32/ld/esp32.common.ld index 45bcc24f47..3fb4ca761c 100644 --- a/components/esp32/ld/esp32.common.ld +++ b/components/esp32/ld/esp32.common.ld @@ -1,5 +1,5 @@ /* Default entry point: */ -ENTRY(call_user_start_cpu0); +ENTRY(call_start_cpu0); SECTIONS { -- 2.40.0