|
| 1 | +diff --git a/components/esp_hw_support/include/esp_private/rtc_clk.h b/components/esp_hw_support/include/esp_private/rtc_clk.h |
| 2 | +index 7edf69be06..c770e94a46 100644 |
| 3 | +--- a/components/esp_hw_support/include/esp_private/rtc_clk.h |
| 4 | ++++ b/components/esp_hw_support/include/esp_private/rtc_clk.h |
| 5 | +@@ -44,6 +44,11 @@ void rtc_clk_bbpll_add_consumer(void); |
| 6 | + */ |
| 7 | + void rtc_clk_bbpll_remove_consumer(void); |
| 8 | + |
| 9 | ++/** |
| 10 | ++ * @brief Workaround for C2, S3, C6, H2. Trigger the calibration of PLL. Should be called when the bootloader doesn't provide a good enough PLL accuracy. |
| 11 | ++*/ |
| 12 | ++void rtc_clk_recalib_bbpll(void); |
| 13 | ++ |
| 14 | + #ifdef __cplusplus |
| 15 | + } |
| 16 | + #endif |
| 17 | +diff --git a/components/esp_hw_support/port/esp32c6/rtc_clk.c b/components/esp_hw_support/port/esp32c6/rtc_clk.c |
| 18 | +index ed6eb4126f..121907fe85 100644 |
| 19 | +--- a/components/esp_hw_support/port/esp32c6/rtc_clk.c |
| 20 | ++++ b/components/esp_hw_support/port/esp32c6/rtc_clk.c |
| 21 | +@@ -167,6 +167,7 @@ static void rtc_clk_bbpll_configure(rtc_xtal_freq_t xtal_freq, int pll_freq) |
| 22 | + clk_ll_bbpll_set_config(pll_freq, xtal_freq); |
| 23 | + /* WAIT CALIBRATION DONE */ |
| 24 | + while(!regi2c_ctrl_ll_bbpll_calibration_is_done()); |
| 25 | ++ esp_rom_delay_us(10); |
| 26 | + /* BBPLL CALIBRATION STOP */ |
| 27 | + regi2c_ctrl_ll_bbpll_calibration_stop(); |
| 28 | + rtc_clk_enable_i2c_ana_master_clock(false); |
| 29 | +@@ -414,6 +415,22 @@ bool rtc_dig_8m_enabled(void) |
| 30 | + return clk_ll_rc_fast_digi_is_enabled(); |
| 31 | + } |
| 32 | + |
| 33 | ++// Workaround for bootloader not calibration well issue. |
| 34 | ++// Placed in IRAM because disabling BBPLL may influence the cache |
| 35 | ++void rtc_clk_recalib_bbpll(void) |
| 36 | ++{ |
| 37 | ++ rtc_cpu_freq_config_t old_config; |
| 38 | ++ rtc_clk_cpu_freq_get_config(&old_config); |
| 39 | ++ |
| 40 | ++ rtc_clk_cpu_freq_set_xtal(); |
| 41 | ++ |
| 42 | ++ rtc_clk_bbpll_disable(); |
| 43 | ++ rtc_clk_bbpll_enable(); |
| 44 | ++ rtc_clk_bbpll_configure(rtc_clk_xtal_freq_get(), 480); |
| 45 | ++ |
| 46 | ++ rtc_clk_cpu_freq_set_config(&old_config); |
| 47 | ++} |
| 48 | ++ |
| 49 | + /* Name used in libphy.a:phy_chip_v7.o |
| 50 | + * TODO: update the library to use rtc_clk_xtal_freq_get |
| 51 | + */ |
| 52 | +diff --git a/components/esp_system/Kconfig b/components/esp_system/Kconfig |
| 53 | +index 3006f40b60..f3ab7b0c80 100644 |
| 54 | +--- a/components/esp_system/Kconfig |
| 55 | ++++ b/components/esp_system/Kconfig |
| 56 | +@@ -561,6 +561,15 @@ menu "ESP System Settings" |
| 57 | + (2). For special workflow, the chip needs do more things instead of restarting directly. This part |
| 58 | + needs to be done in callback function of interrupt. |
| 59 | + |
| 60 | ++ config ESP_SYSTEM_BBPLL_RECALIB |
| 61 | ++ bool "Re-calibration BBPLL at startup" |
| 62 | ++ depends on IDF_TARGET_ESP32C2 || IDF_TARGET_ESP32S3 || IDF_TARGET_ESP32C6 || IDF_TARGET_ESP32H2 |
| 63 | ++ default y |
| 64 | ++ help |
| 65 | ++ This configuration helps to address an BBPLL inaccurate issue when boot from certain bootloader version, |
| 66 | ++ which may increase about the boot-up time by about 200 us. Disable this when your bootloader is built with |
| 67 | ++ ESP-IDF version v5.2 and above. |
| 68 | ++ |
| 69 | + endmenu # ESP System Settings |
| 70 | + |
| 71 | + menu "IPC (Inter-Processor Call)" |
| 72 | +diff --git a/components/esp_system/port/cpu_start.c b/components/esp_system/port/cpu_start.c |
| 73 | +index 97a3f767f5..c894ac15ca 100644 |
| 74 | +--- a/components/esp_system/port/cpu_start.c |
| 75 | ++++ b/components/esp_system/port/cpu_start.c |
| 76 | +@@ -63,6 +63,10 @@ |
| 77 | + #include "esp32c2/rom/secure_boot.h" |
| 78 | + #endif |
| 79 | + |
| 80 | ++#if CONFIG_ESP_SYSTEM_BBPLL_RECALIB |
| 81 | ++#include "esp_private/rtc_clk.h" |
| 82 | ++#endif |
| 83 | ++ |
| 84 | + #include "esp_private/esp_mmu_map_private.h" |
| 85 | + #if CONFIG_SPIRAM |
| 86 | + #include "esp_psram.h" |
| 87 | +@@ -454,7 +458,14 @@ void IRAM_ATTR call_start_cpu0(void) |
| 88 | + * In this stage, we re-configure the Flash (and MSPI) to required configuration |
| 89 | + */ |
| 90 | + spi_flash_init_chip_state(); |
| 91 | ++ |
| 92 | ++ // In earlier version of ESP-IDF, the PLL provided by bootloader is not stable enough. |
| 93 | ++ // Do calibration again here so that we can use better clock for the timing tuning. |
| 94 | ++#if CONFIG_ESP_SYSTEM_BBPLL_RECALIB |
| 95 | ++ rtc_clk_recalib_bbpll(); |
| 96 | ++#endif |
| 97 | + #if SOC_MEMSPI_SRC_FREQ_120M |
| 98 | ++ // This function needs to be called when PLL is enabled |
| 99 | + mspi_timing_flash_tuning(); |
| 100 | + #endif |
| 101 | + |
0 commit comments