2023-01-02 09:15:18 -03:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2017 Intel Corporation
|
2025-01-10 10:48:37 -03:00
|
|
|
* Copyright (c) 2025 Espressif Systems (Shanghai) CO LTD.
|
2023-01-02 09:15:18 -03:00
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
*/
|
|
|
|
|
2023-08-30 17:10:01 -03:00
|
|
|
#include <soc.h>
|
2025-01-10 10:48:37 -03:00
|
|
|
#include <soc_init.h>
|
|
|
|
#include <flash_init.h>
|
2024-10-24 19:40:22 -03:00
|
|
|
#include <esp_private/cache_utils.h>
|
2024-03-06 23:50:55 -03:00
|
|
|
#include <esp_private/system_internal.h>
|
|
|
|
#include <esp_timer.h>
|
2025-05-09 16:55:46 -03:00
|
|
|
#include <efuse_virtual.h>
|
2025-01-10 10:48:37 -03:00
|
|
|
#include <psram.h>
|
|
|
|
#include <zephyr/drivers/interrupt_controller/intc_esp32.h>
|
2023-01-02 09:15:18 -03:00
|
|
|
#include <zephyr/sys/printk.h>
|
|
|
|
|
2024-07-06 15:31:13 -04:00
|
|
|
extern void z_prep_c(void);
|
2023-11-23 09:35:12 -03:00
|
|
|
extern void esp_reset_reason_init(void);
|
2023-08-30 17:10:01 -03:00
|
|
|
|
2023-05-29 20:42:14 +02:00
|
|
|
static void IRAM_ATTR esp_errata(void)
|
|
|
|
{
|
|
|
|
/* Handle the clock gating fix */
|
|
|
|
REG_CLR_BIT(SYSTEM_CORE_1_CONTROL_0_REG, SYSTEM_CONTROL_CORE_1_CLKGATE_EN);
|
|
|
|
/* The clock gating signal of the App core is invalid. We use RUNSTALL and RESETTING
|
|
|
|
* signals to ensure that the App core stops running in single-core mode.
|
|
|
|
*/
|
|
|
|
REG_SET_BIT(SYSTEM_CORE_1_CONTROL_0_REG, SYSTEM_CONTROL_CORE_1_RUNSTALL);
|
|
|
|
REG_CLR_BIT(SYSTEM_CORE_1_CONTROL_0_REG, SYSTEM_CONTROL_CORE_1_RESETTING);
|
|
|
|
|
|
|
|
/* Handle the Dcache case following the IDF startup code */
|
|
|
|
#if CONFIG_ESP32S3_DATA_CACHE_16KB
|
|
|
|
Cache_Invalidate_DCache_All();
|
|
|
|
Cache_Occupy_Addr(SOC_DROM_LOW, 0x4000);
|
|
|
|
#endif
|
|
|
|
}
|
2023-01-02 09:15:18 -03:00
|
|
|
|
2025-01-10 10:48:37 -03:00
|
|
|
void IRAM_ATTR __esp_platform_app_start(void)
|
2023-01-02 09:15:18 -03:00
|
|
|
{
|
2023-05-09 11:10:05 +02:00
|
|
|
/* Configure the mode of instruction cache : cache size, cache line size. */
|
2023-05-29 20:42:14 +02:00
|
|
|
esp_config_instruction_cache_mode();
|
2023-01-02 09:15:18 -03:00
|
|
|
|
2023-05-09 11:10:05 +02:00
|
|
|
/* If we need use SPIRAM, we should use data cache.
|
|
|
|
* Configure the mode of data : cache size, cache line size.
|
|
|
|
*/
|
2023-05-29 20:42:14 +02:00
|
|
|
esp_config_data_cache_mode();
|
2023-05-09 11:10:05 +02:00
|
|
|
|
2024-03-06 23:50:55 -03:00
|
|
|
/* Apply SoC patches */
|
|
|
|
esp_errata();
|
2023-05-29 09:20:49 -03:00
|
|
|
|
2023-11-23 09:35:12 -03:00
|
|
|
esp_reset_reason_init();
|
|
|
|
|
2023-01-02 09:15:18 -03:00
|
|
|
esp_timer_early_init();
|
|
|
|
|
2025-01-10 10:48:37 -03:00
|
|
|
esp_flash_config();
|
2024-09-10 10:22:46 -03:00
|
|
|
|
2025-05-09 16:55:46 -03:00
|
|
|
esp_efuse_init_virtual();
|
|
|
|
|
2024-09-10 10:22:46 -03:00
|
|
|
#if CONFIG_ESP_SPIRAM
|
|
|
|
esp_init_psram();
|
|
|
|
|
2024-08-14 08:03:56 -03:00
|
|
|
int err = esp_psram_smh_init();
|
|
|
|
|
|
|
|
if (err) {
|
|
|
|
printk("Failed to initialize PSRAM shared multi heap (%d)\n", err);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2023-01-02 09:15:18 -03:00
|
|
|
/* Start Zephyr */
|
2024-07-06 15:31:13 -04:00
|
|
|
z_prep_c();
|
2023-01-02 09:15:18 -03:00
|
|
|
|
|
|
|
CODE_UNREACHABLE;
|
|
|
|
}
|
|
|
|
|
2025-01-10 10:48:37 -03:00
|
|
|
void IRAM_ATTR __esp_platform_mcuboot_start(void)
|
|
|
|
{
|
|
|
|
/* Start Zephyr */
|
|
|
|
z_prep_c();
|
|
|
|
|
|
|
|
CODE_UNREACHABLE;
|
|
|
|
}
|
|
|
|
|
2023-01-02 09:15:18 -03:00
|
|
|
/* Boot-time static default printk handler, possibly to be overridden later. */
|
|
|
|
int IRAM_ATTR arch_printk_char_out(int c)
|
|
|
|
{
|
|
|
|
if (c == '\n') {
|
|
|
|
esp_rom_uart_tx_one_char('\r');
|
|
|
|
}
|
|
|
|
esp_rom_uart_tx_one_char(c);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void sys_arch_reboot(int type)
|
|
|
|
{
|
2025-04-01 13:42:04 -03:00
|
|
|
esp_restart();
|
2023-01-02 09:15:18 -03:00
|
|
|
}
|