1 /*
2  * SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 #include "app_cpu_start.h"
8 
9 #include "soc/dport_reg.h"
10 #include "soc/gpio_periph.h"
11 #include "soc/rtc_periph.h"
12 #include "soc/rtc_cntl_reg.h"
13 #include "esp32/rom/cache.h"
14 #include "esp32/rom/uart.h"
15 #include "esp_cpu.h"
16 #include "esp_log.h"
17 
18 static const char *TAG = "app_cpu_start";
19 
appcpu_start(uint32_t entry_addr)20 void appcpu_start(uint32_t entry_addr)
21 {
22     ESP_LOGI(TAG, "Starting APPCPU");
23 
24     Cache_Flush(1);
25     Cache_Read_Enable(1);
26 
27     esp_cpu_unstall(1);
28 
29     DPORT_SET_PERI_REG_MASK(DPORT_APPCPU_CTRL_B_REG, DPORT_APPCPU_CLKGATE_EN);
30     DPORT_CLEAR_PERI_REG_MASK(DPORT_APPCPU_CTRL_C_REG, DPORT_APPCPU_RUNSTALL);
31     DPORT_SET_PERI_REG_MASK(DPORT_APPCPU_CTRL_A_REG, DPORT_APPCPU_RESETTING);
32     DPORT_CLEAR_PERI_REG_MASK(DPORT_APPCPU_CTRL_A_REG, DPORT_APPCPU_RESETTING);
33 
34     ets_set_appcpu_boot_addr(entry_addr);
35     ets_delay_us(10000);
36     uart_tx_wait_idle(0);
37     ESP_LOGI(TAG, "APPCPU start sequence complete");
38 }
39