Skip to content

Commit 564d777

Browse files
committed
Merge branch 'feature/lp_core_40_mhz' into 'master'
feat(system): support choosing xtal as rtc-fast clock src on P4 and C5 Closes IDF-10203 See merge request espressif/esp-idf!32450
2 parents 8320e42 + 00eb977 commit 564d777

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
@@ -37,3 +37,24 @@ config RTC_CLK_CAL_CYCLES
3737
- 32768 Hz if the 32k crystal oscillator is used. For this use value 3000 or more.
3838
In case more value will help improve the definition of the launch of the crystal.
3939
If the crystal could not start, it will be switched to internal RC.
40+
41+
choice RTC_FAST_CLK_SRC
42+
depends on SOC_CLK_LP_FAST_SUPPORT_XTAL
43+
prompt "RTC fast clock source"
44+
default RTC_FAST_CLK_SRC_RC_FAST
45+
help
46+
Choose which clock is used as RTC fast clock source.
47+
48+
Choosing the faster 40 MHz XTAL can allow modules which depend on RTC_FAST
49+
to work at a higher clock frequency. With this the ULP LP-Core will run with a
50+
CPU frequency of 40 Mhz instead of the default 20 Mhz.
51+
52+
The drawback is that the XTAL is usually powered down during sleep, as
53+
it draw a lot of power. Choosing this option will cause the XTAL to stay
54+
powered on, increasing sleep power consumption.
55+
56+
config RTC_FAST_CLK_SRC_RC_FAST
57+
bool "20 Mhz RC Fast Clock"
58+
config RTC_FAST_CLK_SRC_XTAL
59+
bool "40 Mhz crystal (increased power consumption during sleep)"
60+
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
@@ -86,7 +86,13 @@ __attribute__((weak)) void esp_clk_init(void)
8686
assert(rtc_clk_xtal_freq_get() == SOC_XTAL_FREQ_40M);
8787

8888
rtc_clk_8m_enable(true);
89+
#if CONFIG_RTC_FAST_CLK_SRC_RC_FAST
8990
rtc_clk_fast_src_set(SOC_RTC_FAST_CLK_SRC_RC_FAST);
91+
#elif CONFIG_RTC_FAST_CLK_SRC_XTAL
92+
rtc_clk_fast_src_set(SOC_RTC_FAST_CLK_SRC_XTAL);
93+
#else
94+
#error "No RTC fast clock source configured"
95+
#endif
9096

9197
#ifdef CONFIG_BOOTLOADER_WDT_ENABLE
9298
// 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
@@ -1863,6 +1863,10 @@ config SOC_CLK_LP_FAST_SUPPORT_LP_PLL
18631863
bool
18641864
default y
18651865

1866+
config SOC_CLK_LP_FAST_SUPPORT_XTAL
1867+
bool
1868+
default y
1869+
18661870
config SOC_PERIPH_CLK_CTRL_SHARED
18671871
bool
18681872
default y

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

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

711711
#define SOC_CLK_LP_FAST_SUPPORT_LP_PLL (1) /*!< Support LP_PLL clock as the LP_FAST clock source */
712+
#define SOC_CLK_LP_FAST_SUPPORT_XTAL (1) /*!< Support XTAL clock as the LP_FAST clock source */
713+
712714

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

components/ulp/lp_core/lp_core/lp_core_utils.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,17 @@
3030
#include "esp_cpu.h"
3131

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

3545
static uint32_t lp_wakeup_cause = 0;
3646

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)