From 6316e6eba25fe6b0a47d7c1762e845c23c0bddf9 Mon Sep 17 00:00:00 2001 From: morris Date: Tue, 14 Jul 2020 20:39:30 +0800 Subject: [PATCH] esp_system: add CONFIG_ESP_SYSTEM_RTC_EXT_CRYS --- .../bootloader_support/src/bootloader_clock.c | 14 +++-------- components/esp32/Kconfig | 18 +------------- components/esp32s2/Kconfig | 1 + components/esp_system/Kconfig | 24 +++++++++++++++++++ components/esp_system/sdkconfig.rename | 1 + components/soc/test/test_rtc_clk.c | 4 ++-- 6 files changed, 32 insertions(+), 30 deletions(-) diff --git a/components/bootloader_support/src/bootloader_clock.c b/components/bootloader_support/src/bootloader_clock.c index 6888780534..9cb5e842d2 100644 --- a/components/bootloader_support/src/bootloader_clock.c +++ b/components/bootloader_support/src/bootloader_clock.c @@ -69,19 +69,11 @@ void bootloader_clock_configure(void) */ } - /* TODO: move the clock option into esp_system, so that this doesn't have - * to continue: - */ -#if CONFIG_ESP32_RTC_CLK_SRC_EXT_CRYS +#if CONFIG_ESP_SYSTEM_RTC_EXT_XTAL if (!rtc_clk_32k_enabled()) { - rtc_clk_32k_bootstrap(CONFIG_ESP32_RTC_XTAL_BOOTSTRAP_CYCLES); + rtc_clk_32k_bootstrap(CONFIG_ESP_SYSTEM_RTC_EXT_XTAL_BOOTSTRAP_CYCLES); } -#endif -#if CONFIG_ESP32S2_RTC_CLK_SRC_EXT_CRYS - if (!rtc_clk_32k_enabled()) { - rtc_clk_32k_bootstrap(0); - } -#endif +#endif // CONFIG_ESP_SYSTEM_RTC_EXT_XTAL } #ifdef BOOTLOADER_BUILD diff --git a/components/esp32/Kconfig b/components/esp32/Kconfig index dbe79dcdb4..f7aeba9f2c 100644 --- a/components/esp32/Kconfig +++ b/components/esp32/Kconfig @@ -540,6 +540,7 @@ menu "ESP32-specific" bool "Internal 150kHz RC oscillator" config ESP32_RTC_CLK_SRC_EXT_CRYS bool "External 32kHz crystal" + select ESP_SYSTEM_RTC_EXT_XTAL config ESP32_RTC_CLK_SRC_EXT_OSC bool "External 32kHz oscillator at 32K_XP pin" config ESP32_RTC_CLK_SRC_INT_8MD256 @@ -591,23 +592,6 @@ menu "ESP32-specific" Increase this option if the 32k crystal oscillator does not start and switches to internal RC. - config ESP32_RTC_XTAL_BOOTSTRAP_CYCLES - int "Bootstrap cycles for external 32kHz crystal" - depends on ESP32_RTC_CLK_SRC_EXT_CRYS - default 5 - range 0 32768 - help - To reduce the startup time of an external RTC crystal, - we bootstrap it with a 32kHz square wave for a fixed number of cycles. - Setting 0 will disable bootstrapping (if disabled, the crystal may take - longer to start up or fail to oscillate under some conditions). - - If this value is too high, a faulty crystal may initially start and then fail. - If this value is too low, an otherwise good crystal may not start. - - To accurately determine if the crystal has started, - set a larger "Number of cycles for RTC_SLOW_CLK calibration" (about 3000). - config ESP32_DEEP_SLEEP_WAKEUP_DELAY int "Extra delay in deep sleep wake stub (in us)" default 2000 diff --git a/components/esp32s2/Kconfig b/components/esp32s2/Kconfig index 563773072e..0d2ddc315a 100644 --- a/components/esp32s2/Kconfig +++ b/components/esp32s2/Kconfig @@ -443,6 +443,7 @@ menu "ESP32S2-specific" bool "Internal 90kHz RC oscillator" config ESP32S2_RTC_CLK_SRC_EXT_CRYS bool "External 32kHz crystal" + select ESP_SYSTEM_RTC_EXT_XTAL config ESP32S2_RTC_CLK_SRC_EXT_OSC bool "External 32kHz oscillator at 32K_XP pin" config ESP32S2_RTC_CLK_SRC_INT_8MD256 diff --git a/components/esp_system/Kconfig b/components/esp_system/Kconfig index 58a2b90cb3..4d8f572d0c 100644 --- a/components/esp_system/Kconfig +++ b/components/esp_system/Kconfig @@ -38,4 +38,28 @@ menu "ESP System Settings" help Only initialize and use the main core. + config ESP_SYSTEM_RTC_EXT_XTAL + # This is a High Layer Kconfig option, invisible, can be selected by other Kconfig option + # e.g. It will be selected on when ESP32_RTC_CLK_SRC_EXT_CRYS is on + bool + default n + + config ESP_SYSTEM_RTC_EXT_XTAL_BOOTSTRAP_CYCLES + int "Bootstrap cycles for external 32kHz crystal" + depends on ESP_SYSTEM_RTC_EXT_XTAL + default 5 if IDF_TARGET_ESP32 + default 0 + range 0 32768 + help + To reduce the startup time of an external RTC crystal, + we bootstrap it with a 32kHz square wave for a fixed number of cycles. + Setting 0 will disable bootstrapping (if disabled, the crystal may take + longer to start up or fail to oscillate under some conditions). + + If this value is too high, a faulty crystal may initially start and then fail. + If this value is too low, an otherwise good crystal may not start. + + To accurately determine if the crystal has started, + set a larger "Number of cycles for RTC_SLOW_CLK calibration" (about 3000). + endmenu # ESP System Settings diff --git a/components/esp_system/sdkconfig.rename b/components/esp_system/sdkconfig.rename index 87310ef6de..a30538f2ee 100644 --- a/components/esp_system/sdkconfig.rename +++ b/components/esp_system/sdkconfig.rename @@ -11,3 +11,4 @@ CONFIG_ESP32S2_PANIC_PRINT_REBOOT CONFIG_ESP_SYSTEM_PANIC_ CONFIG_ESP32S2_PANIC_SILENT_REBOOT CONFIG_ESP_SYSTEM_PANIC_SILENT_REBOOT CONFIG_ESP32S2_PANIC_GDBSTUB CONFIG_ESP_SYSTEM_PANIC_GDBSTUB +CONFIG_ESP32_RTC_XTAL_BOOTSTRAP_CYCLES CONFIG_ESP_SYSTEM_RTC_EXT_XTAL_BOOTSTRAP_CYCLES \ No newline at end of file diff --git a/components/soc/test/test_rtc_clk.c b/components/soc/test/test_rtc_clk.c index cb2010a467..ce6d60c195 100644 --- a/components/soc/test/test_rtc_clk.c +++ b/components/soc/test/test_rtc_clk.c @@ -171,7 +171,7 @@ static void start_freq(rtc_slow_freq_t required_src_freq, uint32_t start_delay_m rtc_slow_freq_t selected_src_freq; stop_rtc_external_quartz(); #ifdef CONFIG_ESP32_RTC_CLK_SRC_EXT_CRYS - uint32_t bootstrap_cycles = CONFIG_ESP32_RTC_XTAL_BOOTSTRAP_CYCLES; + uint32_t bootstrap_cycles = CONFIG_ESP_SYSTEM_RTC_EXT_XTAL_BOOTSTRAP_CYCLES; printf("Test is started. Kconfig settings:\n External 32K crystal is selected,\n Oscillation cycles = %d,\n Calibration cycles = %d.\n", bootstrap_cycles, CONFIG_ESP32_RTC_CLK_CAL_CYCLES); @@ -232,7 +232,7 @@ TEST_CASE("Test starting external RTC quartz", "[rtc_clk][test_env=UT_T1_32kXTAL uint32_t end_time; stop_rtc_external_quartz(); #ifdef CONFIG_ESP32_RTC_CLK_SRC_EXT_CRYS - uint32_t bootstrap_cycles = CONFIG_ESP32_RTC_XTAL_BOOTSTRAP_CYCLES; + uint32_t bootstrap_cycles = CONFIG_ESP_SYSTEM_RTC_EXT_XTAL_BOOTSTRAP_CYCLES; printf("Test is started. Kconfig settings:\n External 32K crystal is selected,\n Oscillation cycles = %d,\n Calibration cycles = %d.\n", bootstrap_cycles, CONFIG_ESP32_RTC_CLK_CAL_CYCLES);