Просмотр исходного кода

esp32s2: Add a Kconfig option- Number of attempts to repeat 32k XTAL calibration

KonstantinKondrashov 5 лет назад
Родитель
Сommit
df2ea2527f
2 измененных файлов с 17 добавлено и 5 удалено
  1. 10 0
      components/esp32s2/Kconfig
  2. 7 5
      components/esp32s2/clk.c

+ 10 - 0
components/esp32s2/Kconfig

@@ -457,6 +457,16 @@ menu "ESP32S2-specific"
               In case more value will help improve the definition of the launch of the crystal.
               If the crystal could not start, it will be switched to internal RC.
 
+    config ESP32S2_RTC_XTAL_CAL_RETRY
+        int "Number of attempts to repeat 32k XTAL calibration"
+        default 3
+        depends on ESP32S2_RTC_CLK_SRC_EXT_CRYS
+        help
+            Number of attempts to repeat 32k XTAL calibration
+            before giving up and switching to the internal RC.
+            Increase this option if the 32k crystal oscillator
+            does not start and switches to internal RC.
+
     config ESP32S2_DISABLE_BASIC_ROM_CONSOLE
         bool "Permanently disable BASIC ROM Console"
         default n

+ 7 - 5
components/esp32s2/clk.c

@@ -42,6 +42,12 @@
  */
 #define SLOW_CLK_CAL_CYCLES     CONFIG_ESP32S2_RTC_CLK_CAL_CYCLES
 
+#ifdef CONFIG_ESP32S2_RTC_XTAL_CAL_RETRY
+#define RTC_XTAL_CAL_RETRY CONFIG_ESP32S2_RTC_XTAL_CAL_RETRY
+#else
+#define RTC_XTAL_CAL_RETRY 1
+#endif
+
 #define MHZ (1000000)
 
 /* Lower threshold for a reasonably-looking calibration value for a 32k XTAL.
@@ -148,11 +154,7 @@ static void select_rtc_slow_clk(slow_clk_sel_t slow_clk)
     /* number of times to repeat 32k XTAL calibration
      * before giving up and switching to the internal RC
      */
-#ifdef CONFIG_IDF_TARGET_ESP32
-    int retry_32k_xtal = 1;     /* don't change the behavior for the ESP32 */
-#else
-    int retry_32k_xtal = 3;
-#endif
+    int retry_32k_xtal = RTC_XTAL_CAL_RETRY;
 
     do {
         if (rtc_slow_freq == RTC_SLOW_FREQ_32K_XTAL) {