From dfac6f6ef4e0ca95d8ce36334e43e68aeeaff52b Mon Sep 17 00:00:00 2001 From: hebinglin Date: Tue, 20 Jan 2026 21:22:23 +0800 Subject: [PATCH] change(esp_system): add iram opt for rtc clk resart cases --- .../esp_hw_support/port/esp32h4/rtc_clk.c | 2 +- .../test_apps/rtc_clk/main/test_rtc_clk.c | 30 +++++++++++++++++++ .../test_apps/rtc_clk/pytest_rtc_clk.py | 20 ++++++++++++- .../test_apps/rtc_clk/sdkconfig.ci | 0 .../rtc_clk/sdkconfig.ci.rtc_clk_flash | 4 +++ .../sdkconfig.ci.default | 3 ++ 6 files changed, 57 insertions(+), 2 deletions(-) create mode 100644 components/esp_hw_support/test_apps/rtc_clk/sdkconfig.ci create mode 100644 components/esp_hw_support/test_apps/rtc_clk/sdkconfig.ci.rtc_clk_flash diff --git a/components/esp_hw_support/port/esp32h4/rtc_clk.c b/components/esp_hw_support/port/esp32h4/rtc_clk.c index cac9fe1cfd..f8dcf6a68e 100644 --- a/components/esp_hw_support/port/esp32h4/rtc_clk.c +++ b/components/esp_hw_support/port/esp32h4/rtc_clk.c @@ -169,7 +169,7 @@ static void rtc_clk_bbpll_configure(soc_xtal_freq_t xtal_freq, int pll_freq) * Must satisfy: cpu_freq = XTAL_FREQ / div. * Does not disable the PLL. */ -static void rtc_clk_cpu_freq_to_xtal(int cpu_freq, int div) +FORCE_IRAM_ATTR static void rtc_clk_cpu_freq_to_xtal(int cpu_freq, int div) { // let f_cpu = f_ahb clk_ll_ahb_set_divider(1); diff --git a/components/esp_hw_support/test_apps/rtc_clk/main/test_rtc_clk.c b/components/esp_hw_support/test_apps/rtc_clk/main/test_rtc_clk.c index e5beeceaa8..533cf08352 100644 --- a/components/esp_hw_support/test_apps/rtc_clk/main/test_rtc_clk.c +++ b/components/esp_hw_support/test_apps/rtc_clk/main/test_rtc_clk.c @@ -484,3 +484,33 @@ TEST_CASE("Output 8M clock to GPIO25", "[ignore]") pull_out_clk(RTC_IO_DEBUG_SEL0_8M); } #endif + +#if !CONFIG_RTC_CLK_FUNC_IN_IRAM +static void do_restart(void) +{ + esp_restart(); +} + +#if CONFIG_FREERTOS_NUMBER_OF_CORES > 1 +static void do_restart_from_app_cpu(void) +{ + xTaskCreatePinnedToCore((TaskFunction_t) &do_restart, "restart", 2048, NULL, 5, NULL, 1); + vTaskDelay(2); +} +#endif + +static void check_reset_reason_sw(void) +{ + TEST_ASSERT_EQUAL(ESP_RST_SW, esp_reset_reason()); +} + +TEST_CASE_MULTIPLE_STAGES("test rtc_clk in flash after restart", "[rtc_clk]", + do_restart, + check_reset_reason_sw); + +#if CONFIG_FREERTOS_NUMBER_OF_CORES > 1 +TEST_CASE_MULTIPLE_STAGES("test rtc_clk in flash after restart from APP CPU", "[rtc_clk]", + do_restart_from_app_cpu, + check_reset_reason_sw); +#endif +#endif diff --git a/components/esp_hw_support/test_apps/rtc_clk/pytest_rtc_clk.py b/components/esp_hw_support/test_apps/rtc_clk/pytest_rtc_clk.py index bd3bb67f91..2624745c1a 100644 --- a/components/esp_hw_support/test_apps/rtc_clk/pytest_rtc_clk.py +++ b/components/esp_hw_support/test_apps/rtc_clk/pytest_rtc_clk.py @@ -1,4 +1,4 @@ -# SPDX-FileCopyrightText: 2022-2025 Espressif Systems (Shanghai) CO LTD +# SPDX-FileCopyrightText: 2022-2026 Espressif Systems (Shanghai) CO LTD # SPDX-License-Identifier: CC0-1.0 import pytest @@ -33,3 +33,21 @@ def test_rtc_no_xtal32k(dut: IdfDut) -> None: @idf_parametrize('target', soc_filtered_targets('SOC_CLK_TREE_SUPPORTED == 1'), indirect=['target']) def test_rtc_calib_compensation_across_dslp(case_tester: CaseTester) -> None: case_tester.run_all_multi_stage_cases() + + +@pytest.mark.flash_suspend +@pytest.mark.temp_skip_ci(targets=['esp32h2'], reason='flash clock lose in startup') # TODO [ESP32H2]: IDF-15212 +@pytest.mark.parametrize( + 'config', + [ + 'rtc_clk_flash', + ], + indirect=True, +) +@idf_parametrize( + 'target', + soc_filtered_targets('SOC_CLK_TREE_SUPPORTED == 1 and IDF_TARGET not in ["esp32", "esp32s2"]'), + indirect=['target'], +) +def test_rtc_clk_flash(case_tester: CaseTester) -> None: + case_tester.run_all_multi_stage_cases() diff --git a/components/esp_hw_support/test_apps/rtc_clk/sdkconfig.ci b/components/esp_hw_support/test_apps/rtc_clk/sdkconfig.ci new file mode 100644 index 0000000000..e69de29bb2 diff --git a/components/esp_hw_support/test_apps/rtc_clk/sdkconfig.ci.rtc_clk_flash b/components/esp_hw_support/test_apps/rtc_clk/sdkconfig.ci.rtc_clk_flash new file mode 100644 index 0000000000..8060944cbb --- /dev/null +++ b/components/esp_hw_support/test_apps/rtc_clk/sdkconfig.ci.rtc_clk_flash @@ -0,0 +1,4 @@ +CONFIG_RTC_CLK_FUNC_IN_IRAM=n +CONFIG_SPI_FLASH_AUTO_SUSPEND=y +# Now the runners are massively using xmc-c chips, to be removed when xmc-d goes massive production. +CONFIG_SPI_FLASH_FORCE_ENABLE_XMC_C_SUSPEND=y diff --git a/components/esp_system/test_apps/esp_system_unity_tests/sdkconfig.ci.default b/components/esp_system/test_apps/esp_system_unity_tests/sdkconfig.ci.default index e8104032cf..91bae93bff 100644 --- a/components/esp_system/test_apps/esp_system_unity_tests/sdkconfig.ci.default +++ b/components/esp_system/test_apps/esp_system_unity_tests/sdkconfig.ci.default @@ -2,3 +2,6 @@ # Used for testing stack smashing protection CONFIG_COMPILER_STACK_CHECK=y CONFIG_PM_POWER_DOWN_PERIPHERAL_IN_LIGHT_SLEEP=y +CONFIG_ESP_PERIPH_CTRL_FUNC_IN_IRAM=n +CONFIG_RTC_CLK_FUNC_IN_IRAM=n +CONFIG_RTC_TIME_FUNC_IN_IRAM=n