Skip to content

Commit 00eb977

Browse files
committed
feat(system): support choosing xtal as rtc-fast clock src on P4 and C5
With xtal as rtc-fast clock source the LP-Core can run at twice the default clock frequency. 40 MHz as opposed to 20 MHz.
1 parent 4b77ecd commit 00eb977

File tree

13 files changed

+115
-4
lines changed

13 files changed

+115
-4
lines changed

components/esp_hw_support/port/esp32c5/Kconfig.rtc

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,24 @@ config RTC_CLK_CAL_CYCLES
3535
- 32768 Hz if the 32k crystal oscillator is used. For this use value 3000 or more.
3636
In case more value will help improve the definition of the launch of the crystal.
3737
If the crystal could not start, it will be switched to internal RC.
38+
39+
choice RTC_FAST_CLK_SRC
40+
depends on SOC_CLK_LP_FAST_SUPPORT_XTAL
41+
prompt "RTC fast clock source"
42+
default RTC_FAST_CLK_SRC_RC_FAST
43+
help
44+
Choose which clock is used as RTC fast clock source.
45+
46+
Choosing the faster 48 MHz external crystal clock (XTAL) can allow modules which depend on RTC_FAST
47+
to work at a higher clock frequency. With this the ULP LP-Core will run with a
48+
CPU frequency of 48 Mhz instead of the default 20 Mhz.
49+
50+
The drawback is that the XTAL is usually powered down during sleep, as
51+
it draw a lot of power. Choosing this option will cause the XTAL to stay
52+
powered on, increasing sleep power consumption.
53+
54+
config RTC_FAST_CLK_SRC_RC_FAST
55+
bool "20 Mhz RC Fast Clock"
56+
config RTC_FAST_CLK_SRC_XTAL
57+
bool "48 Mhz crystal (increased power consumption during sleep)"
58+
endchoice

components/esp_hw_support/port/esp32p4/Kconfig.rtc

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,24 @@ config RTC_CLK_CAL_CYCLES
3434
- 32768 Hz if the 32k crystal oscillator is used. For this use value 3000 or more.
3535
In case more value will help improve the definition of the launch of the crystal.
3636
If the crystal could not start, it will be switched to internal RC.
37+
38+
choice RTC_FAST_CLK_SRC
39+
depends on SOC_CLK_LP_FAST_SUPPORT_XTAL
40+
prompt "RTC fast clock source"
41+
default RTC_FAST_CLK_SRC_RC_FAST
42+
help
43+
Choose which clock is used as RTC fast clock source.
44+
45+
Choosing the faster 40 MHz XTAL can allow modules which depend on RTC_FAST
46+
to work at a higher clock frequency. With this the ULP LP-Core will run with a
47+
CPU frequency of 40 Mhz instead of the default 20 Mhz.
48+
49+
The drawback is that the XTAL is usually powered down during sleep, as
50+
it draw a lot of power. Choosing this option will cause the XTAL to stay
51+
powered on, increasing sleep power consumption.
52+
53+
config RTC_FAST_CLK_SRC_RC_FAST
54+
bool "20 Mhz RC Fast Clock"
55+
config RTC_FAST_CLK_SRC_XTAL
56+
bool "40 Mhz crystal (increased power consumption during sleep)"
57+
endchoice

components/esp_hw_support/port/esp_clk_tree_common.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ uint32_t esp_clk_tree_lp_fast_get_freq_hz(esp_clk_tree_src_freq_precision_t prec
191191
case SOC_RTC_FAST_CLK_SRC_LP_PLL:
192192
return clk_ll_lp_pll_get_freq_mhz() * MHZ;
193193
#endif
194-
#if SOC_CLK_LP_FAST_SUPPORT_XTAL
194+
#if SOC_CLK_LP_FAST_SUPPORT_XTAL && !CONFIG_IDF_TARGET_ESP32P4 // On P4 SOC_RTC_FAST_CLK_SRC_XTAL is an alias for SOC_RTC_FAST_CLK_SRC_XTAL_DIV
195195
case SOC_RTC_FAST_CLK_SRC_XTAL:
196196
return clk_hal_xtal_get_freq_mhz() * MHZ;
197197
#endif

components/esp_system/port/soc/esp32c5/clk.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,14 @@ __attribute__((weak)) void esp_clk_init(void)
5656
assert((rtc_clk_xtal_freq_get() == SOC_XTAL_FREQ_48M) || (rtc_clk_xtal_freq_get() == SOC_XTAL_FREQ_40M));
5757

5858
rtc_clk_8m_enable(true);
59+
#if CONFIG_RTC_FAST_CLK_SRC_RC_FAST
5960
rtc_clk_fast_src_set(SOC_RTC_FAST_CLK_SRC_RC_FAST);
61+
#elif CONFIG_RTC_FAST_CLK_SRC_XTAL
62+
rtc_clk_fast_src_set(SOC_RTC_FAST_CLK_SRC_XTAL);
63+
#else
64+
#error "No RTC fast clock source configured"
6065
#endif
66+
#endif //!CONFIG_IDF_ENV_FPGA
6167

6268
#ifdef CONFIG_BOOTLOADER_WDT_ENABLE
6369
// WDT uses a SLOW_CLK clock source. After a function select_rtc_slow_clk a frequency of this source can changed.

components/esp_system/port/soc/esp32p4/clk.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,13 @@ __attribute__((weak)) void esp_clk_init(void)
5353
assert(rtc_clk_xtal_freq_get() == SOC_XTAL_FREQ_40M);
5454

5555
rtc_clk_8m_enable(true);
56+
#if CONFIG_RTC_FAST_CLK_SRC_RC_FAST
5657
rtc_clk_fast_src_set(SOC_RTC_FAST_CLK_SRC_RC_FAST);
58+
#elif CONFIG_RTC_FAST_CLK_SRC_XTAL
59+
rtc_clk_fast_src_set(SOC_RTC_FAST_CLK_SRC_XTAL);
60+
#else
61+
#error "No RTC fast clock source configured"
62+
#endif
5763

5864
#ifdef CONFIG_BOOTLOADER_WDT_ENABLE
5965
// WDT uses a SLOW_CLK clock source. After a function select_rtc_slow_clk a frequency of this source can changed.

components/soc/esp32p4/include/soc/Kconfig.soc_caps.in

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1751,6 +1751,10 @@ config SOC_CLK_LP_FAST_SUPPORT_LP_PLL
17511751
bool
17521752
default y
17531753

1754+
config SOC_CLK_LP_FAST_SUPPORT_XTAL
1755+
bool
1756+
default y
1757+
17541758
config SOC_PERIPH_CLK_CTRL_SHARED
17551759
bool
17561760
default y

components/soc/esp32p4/include/soc/soc_caps.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -682,6 +682,8 @@
682682
#define SOC_CLK_RC32K_SUPPORTED (1) /*!< Support an internal 32kHz RC oscillator */
683683

684684
#define SOC_CLK_LP_FAST_SUPPORT_LP_PLL (1) /*!< Support LP_PLL clock as the LP_FAST clock source */
685+
#define SOC_CLK_LP_FAST_SUPPORT_XTAL (1) /*!< Support XTAL clock as the LP_FAST clock source */
686+
685687

686688
#define SOC_PERIPH_CLK_CTRL_SHARED (1) /*!< Peripheral clock control (e.g. set clock source) is shared between various peripherals */
687689

components/ulp/lp_core/lp_core/lp_core_utils.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,17 @@
2828
#endif
2929

3030
/* LP_FAST_CLK is not very accurate, for now use a rough estimate */
31+
#if CONFIG_RTC_FAST_CLK_SRC_RC_FAST
3132
#define LP_CORE_CPU_FREQUENCY_HZ 16000000 // For P4 TRM says 20 MHz by default, but we tune it closer to 16 MHz
33+
#elif CONFIG_RTC_FAST_CLK_SRC_XTAL
34+
#if SOC_XTAL_SUPPORT_48M
35+
#define LP_CORE_CPU_FREQUENCY_HZ 48000000
36+
#else
37+
#define LP_CORE_CPU_FREQUENCY_HZ 40000000
38+
#endif
39+
#else // Default value in chip without rtc fast clock sel option
40+
#define LP_CORE_CPU_FREQUENCY_HZ 16000000
41+
#endif
3242

3343
static uint32_t lp_wakeup_cause = 0;
3444

components/ulp/test_apps/.build-test-rules.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
# Documentation: .gitlab/ci/README.md#manifest-file-to-control-the-buildtest-apps
22

3-
components/ulp/test_apps/lp_core:
3+
components/ulp/test_apps/lp_core/lp_core_basic_tests:
4+
disable:
5+
- if: SOC_LP_CORE_SUPPORTED != 1
6+
- if: CONFIG_NAME == "xtal" and SOC_CLK_LP_FAST_SUPPORT_XTAL != 1
7+
8+
components/ulp/test_apps/lp_core/lp_core_hp_uart:
49
disable:
510
- if: SOC_LP_CORE_SUPPORTED != 1
611

components/ulp/test_apps/lp_core/lp_core_basic_tests/main/test_lp_core.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ TEST_CASE("Test LP core delay", "[lp_core]")
132132
#define LP_TIMER_TEST_SLEEP_DURATION_US (20000)
133133

134134
#if !TEMPORARY_DISABLED_FOR_TARGETS(ESP32C5)
135+
#if SOC_DEEP_SLEEP_SUPPORTED && CONFIG_RTC_FAST_CLK_SRC_RC_FAST
135136

136137
static void do_ulp_wakeup_deepsleep(lp_core_test_commands_t ulp_cmd)
137138
{
@@ -228,7 +229,8 @@ TEST_CASE_MULTIPLE_STAGES("LP Timer can wakeup lp core periodically during deep
228229
do_ulp_wakeup_with_lp_timer_deepsleep,
229230
check_reset_reason_and_sleep_duration);
230231

231-
#endif //#if !TEMPORARY_DISABLED_FOR_TARGETS(ESP32C5)
232+
#endif //#if SOC_DEEP_SLEEP_SUPPORTED && CONFIG_RTC_FAST_CLK_SRC_RC_FAST
233+
#endif //!TEMPORARY_DISABLED_FOR_TARGETS(ESP32C5)
232234

233235
TEST_CASE("LP Timer can wakeup lp core periodically", "[lp_core]")
234236
{
@@ -382,5 +384,4 @@ TEST_CASE("LP core ISR tests", "[ulp]")
382384
printf("ULP LP IO ISR triggered %"PRIu32" times\n", ulp_io_isr_counter);
383385
TEST_ASSERT_EQUAL(ISR_TEST_ITERATIONS, ulp_io_isr_counter);
384386
#endif //SOC_RTCIO_PIN_COUNT > 0
385-
386387
}

0 commit comments

Comments
 (0)