mirror of
https://github.com/espressif/esp-idf.git
synced 2025-09-30 19:19:21 +00:00
fix(startup): move rtc initialization before MSPI timing tuning to improve stability
This commit is contained in:
@@ -58,14 +58,26 @@
|
||||
#define MHZ (1000000)
|
||||
|
||||
static void select_rtc_slow_clk(soc_rtc_slow_clk_src_t rtc_slow_clk_src);
|
||||
static __attribute__((unused)) void recalib_bbpll(void);
|
||||
|
||||
static const char *TAG = "clk";
|
||||
|
||||
void esp_rtc_init(void)
|
||||
{
|
||||
#if CONFIG_ESP_SYSTEM_BBPLL_RECALIB
|
||||
// In earlier version of ESP-IDF, the PLL provided by bootloader is not stable enough.
|
||||
// Do calibration again here so that we can use better clock for the timing tuning.
|
||||
recalib_bbpll();
|
||||
#endif
|
||||
|
||||
#if !CONFIG_IDF_ENV_FPGA
|
||||
pmu_init();
|
||||
#endif
|
||||
}
|
||||
|
||||
__attribute__((weak)) void esp_clk_init(void)
|
||||
{
|
||||
#if !CONFIG_IDF_ENV_FPGA
|
||||
pmu_init();
|
||||
|
||||
assert(rtc_clk_xtal_freq_get() == SOC_XTAL_FREQ_32M);
|
||||
|
||||
rtc_clk_8m_enable(true);
|
||||
@@ -290,3 +302,21 @@ __attribute__((weak)) void esp_perip_clk_init(void)
|
||||
WRITE_PERI_REG(LP_CLKRST_LP_CLK_PO_EN_REG, 0);
|
||||
}
|
||||
}
|
||||
|
||||
// Workaround for bootloader not calibrated well issue.
|
||||
// Placed in IRAM because disabling BBPLL may influence the cache
|
||||
static void IRAM_ATTR NOINLINE_ATTR recalib_bbpll(void)
|
||||
{
|
||||
rtc_cpu_freq_config_t old_config;
|
||||
rtc_clk_cpu_freq_get_config(&old_config);
|
||||
|
||||
// There are two paths we arrive here: 1. CPU reset. 2. Other reset reasons.
|
||||
// - For other reasons, the bootloader will set CPU source to BBPLL and enable it. But there are calibration issues.
|
||||
// Turn off the BBPLL and do calibration again to fix the issue. Flash_PLL comes from the same source as PLL.
|
||||
// - For CPU reset, the CPU source will be set to XTAL, while the BBPLL is kept to meet USB Serial JTAG's
|
||||
// requirements. In this case, we don't touch BBPLL to avoid USJ disconnection.
|
||||
if (old_config.source == SOC_CPU_CLK_SRC_PLL || old_config.source == SOC_CPU_CLK_SRC_FLASH_PLL) {
|
||||
rtc_clk_cpu_freq_set_xtal();
|
||||
rtc_clk_cpu_freq_set_config(&old_config);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user