Skip to content

Commit a02beac

Browse files
committed
Merge branch 'bugfix/potential_wifi_not_work_issue' into 'master'
fix: Fixed a potential issue that wifi may not work (for ESP32-C6 on ESP-IDF v5.1) See merge request application/esp-at!1465
2 parents da4fb41 + e40f7ef commit a02beac

File tree

2 files changed

+105
-0
lines changed

2 files changed

+105
-0
lines changed
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
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+

module_config/module_esp32c6_default/patch/patch_list.ini

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,7 @@
1111
[dhcps_poll.patch]
1212
path = esp-idf
1313
note = "Fixed an issue that dhcps cannot restore to the default dhcps poll"
14+
15+
[bbpll_calibration.patch]
16+
path = esp-idf
17+
note = "Fixed a potential issue that wifi may not work (for ESP32-C6 on ESP-IDF v5.1)"

0 commit comments

Comments
 (0)