esp_system: add CONFIG_ESP_SYSTEM_RTC_EXT_CRYS

This commit is contained in:
morris
2020-07-14 20:39:30 +08:00
parent 204cb341b1
commit 6316e6eba2
6 changed files with 32 additions and 30 deletions

View File

@@ -69,19 +69,11 @@ void bootloader_clock_configure(void)
*/ */
} }
/* TODO: move the clock option into esp_system, so that this doesn't have #if CONFIG_ESP_SYSTEM_RTC_EXT_XTAL
* to continue:
*/
#if CONFIG_ESP32_RTC_CLK_SRC_EXT_CRYS
if (!rtc_clk_32k_enabled()) { 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 #endif // CONFIG_ESP_SYSTEM_RTC_EXT_XTAL
#if CONFIG_ESP32S2_RTC_CLK_SRC_EXT_CRYS
if (!rtc_clk_32k_enabled()) {
rtc_clk_32k_bootstrap(0);
}
#endif
} }
#ifdef BOOTLOADER_BUILD #ifdef BOOTLOADER_BUILD

View File

@@ -540,6 +540,7 @@ menu "ESP32-specific"
bool "Internal 150kHz RC oscillator" bool "Internal 150kHz RC oscillator"
config ESP32_RTC_CLK_SRC_EXT_CRYS config ESP32_RTC_CLK_SRC_EXT_CRYS
bool "External 32kHz crystal" bool "External 32kHz crystal"
select ESP_SYSTEM_RTC_EXT_XTAL
config ESP32_RTC_CLK_SRC_EXT_OSC config ESP32_RTC_CLK_SRC_EXT_OSC
bool "External 32kHz oscillator at 32K_XP pin" bool "External 32kHz oscillator at 32K_XP pin"
config ESP32_RTC_CLK_SRC_INT_8MD256 config ESP32_RTC_CLK_SRC_INT_8MD256
@@ -591,23 +592,6 @@ menu "ESP32-specific"
Increase this option if the 32k crystal oscillator Increase this option if the 32k crystal oscillator
does not start and switches to internal RC. 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 config ESP32_DEEP_SLEEP_WAKEUP_DELAY
int "Extra delay in deep sleep wake stub (in us)" int "Extra delay in deep sleep wake stub (in us)"
default 2000 default 2000

View File

@@ -443,6 +443,7 @@ menu "ESP32S2-specific"
bool "Internal 90kHz RC oscillator" bool "Internal 90kHz RC oscillator"
config ESP32S2_RTC_CLK_SRC_EXT_CRYS config ESP32S2_RTC_CLK_SRC_EXT_CRYS
bool "External 32kHz crystal" bool "External 32kHz crystal"
select ESP_SYSTEM_RTC_EXT_XTAL
config ESP32S2_RTC_CLK_SRC_EXT_OSC config ESP32S2_RTC_CLK_SRC_EXT_OSC
bool "External 32kHz oscillator at 32K_XP pin" bool "External 32kHz oscillator at 32K_XP pin"
config ESP32S2_RTC_CLK_SRC_INT_8MD256 config ESP32S2_RTC_CLK_SRC_INT_8MD256

View File

@@ -38,4 +38,28 @@ menu "ESP System Settings"
help help
Only initialize and use the main core. 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 endmenu # ESP System Settings

View File

@@ -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_SILENT_REBOOT CONFIG_ESP_SYSTEM_PANIC_SILENT_REBOOT
CONFIG_ESP32S2_PANIC_GDBSTUB CONFIG_ESP_SYSTEM_PANIC_GDBSTUB CONFIG_ESP32S2_PANIC_GDBSTUB CONFIG_ESP_SYSTEM_PANIC_GDBSTUB
CONFIG_ESP32_RTC_XTAL_BOOTSTRAP_CYCLES CONFIG_ESP_SYSTEM_RTC_EXT_XTAL_BOOTSTRAP_CYCLES

View File

@@ -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; rtc_slow_freq_t selected_src_freq;
stop_rtc_external_quartz(); stop_rtc_external_quartz();
#ifdef CONFIG_ESP32_RTC_CLK_SRC_EXT_CRYS #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", printf("Test is started. Kconfig settings:\n External 32K crystal is selected,\n Oscillation cycles = %d,\n Calibration cycles = %d.\n",
bootstrap_cycles, bootstrap_cycles,
CONFIG_ESP32_RTC_CLK_CAL_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; uint32_t end_time;
stop_rtc_external_quartz(); stop_rtc_external_quartz();
#ifdef CONFIG_ESP32_RTC_CLK_SRC_EXT_CRYS #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", printf("Test is started. Kconfig settings:\n External 32K crystal is selected,\n Oscillation cycles = %d,\n Calibration cycles = %d.\n",
bootstrap_cycles, bootstrap_cycles,
CONFIG_ESP32_RTC_CLK_CAL_CYCLES); CONFIG_ESP32_RTC_CLK_CAL_CYCLES);