From b8e0ee431c49338e0ce591c6f6340e9f12b0681c Mon Sep 17 00:00:00 2001 From: hebinglin Date: Mon, 16 Mar 2026 16:09:43 +0800 Subject: [PATCH] change(ulp): add HP Core wakeup causes save test cases --- .../esp_rom/esp32c6/include/esp32c6/rom/rtc.h | 2 +- .../lp_core_basic_tests/main/CMakeLists.txt | 8 +++ .../main/lp_core/test_main_exception.c | 8 ++- .../main/lp_core/test_main_halt.c | 20 ++++++++ .../main/lp_core/test_shared.h | 1 + .../lp_core_basic_tests/main/test_lp_core.c | 50 +++++++++++++++++++ 6 files changed, 87 insertions(+), 2 deletions(-) create mode 100644 components/ulp/test_apps/lp_core/lp_core_basic_tests/main/lp_core/test_main_halt.c diff --git a/components/esp_rom/esp32c6/include/esp32c6/rom/rtc.h b/components/esp_rom/esp32c6/include/esp32c6/rom/rtc.h index 38c3ac3c35..a8d34a0ece 100644 --- a/components/esp_rom/esp32c6/include/esp32c6/rom/rtc.h +++ b/components/esp_rom/esp32c6/include/esp32c6/rom/rtc.h @@ -53,7 +53,7 @@ extern "C" { * LP_AON_STORE7_REG FAST_RTC_MEMORY_CRC * LP_AON_STORE8_REG Store light sleep wake stub addr * LP_AON_STORE9_REG Store the sleep mode at bit[0] (0:light sleep 1:deep sleep) - * LP_AON_STORE10_REG LP core store wakeup cause at bit[31:2] + * LP_AON_STORE9_REG LP core store wakeup cause at bit[31:2] ************************************************************************************* */ diff --git a/components/ulp/test_apps/lp_core/lp_core_basic_tests/main/CMakeLists.txt b/components/ulp/test_apps/lp_core/lp_core_basic_tests/main/CMakeLists.txt index 941f808188..40a1cb0bec 100644 --- a/components/ulp/test_apps/lp_core/lp_core_basic_tests/main/CMakeLists.txt +++ b/components/ulp/test_apps/lp_core/lp_core_basic_tests/main/CMakeLists.txt @@ -59,6 +59,10 @@ if(CONFIG_SOC_LP_VAD_SUPPORTED) set(lp_core_sources_vad "lp_core/test_main_vad.c") endif() +if(CONFIG_SOC_LP_CORE_HW_AUTO_CLRWAKEUPCAUSE) + set(lp_core_sources_halt "lp_core/test_main_halt.c") +endif() + idf_component_register(SRCS ${app_sources} INCLUDE_DIRS "lp_core" REQUIRES ulp unity esp_timer test_utils @@ -105,3 +109,7 @@ ulp_embed_binary(lp_core_test_app_prefix1 "lp_core/test_main_prefix1.c" "${lp_c ulp_embed_binary(lp_core_test_app_prefix2 "lp_core/test_main_prefix2.c" "${lp_core_exp_dep_srcs}" PREFIX "ulp2_") ulp_embed_binary(lp_core_test_app_exception "lp_core/test_main_exception.c" "${lp_core_exp_dep_srcs}") + +if(CONFIG_SOC_LP_CORE_HW_AUTO_CLRWAKEUPCAUSE) + ulp_embed_binary(lp_core_test_app_halt "lp_core/test_main_halt.c" "${lp_core_exp_dep_srcs}") +endif() diff --git a/components/ulp/test_apps/lp_core/lp_core_basic_tests/main/lp_core/test_main_exception.c b/components/ulp/test_apps/lp_core/lp_core_basic_tests/main/lp_core/test_main_exception.c index fc6b14ad0a..df9177898b 100644 --- a/components/ulp/test_apps/lp_core/lp_core_basic_tests/main/lp_core/test_main_exception.c +++ b/components/ulp/test_apps/lp_core/lp_core_basic_tests/main/lp_core/test_main_exception.c @@ -1,10 +1,16 @@ /* - * SPDX-FileCopyrightText: 2025 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2025-2026 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ +#include "ulp_lp_core_utils.h" + int main(void) { + // Wait for 1 second to ensure the HP Core enters deep sleep + ulp_lp_core_delay_us(1000000); + + // Trigger an exception to wake up the HP Core asm volatile("unimp"); } diff --git a/components/ulp/test_apps/lp_core/lp_core_basic_tests/main/lp_core/test_main_halt.c b/components/ulp/test_apps/lp_core/lp_core_basic_tests/main/lp_core/test_main_halt.c new file mode 100644 index 0000000000..12b8ebfa26 --- /dev/null +++ b/components/ulp/test_apps/lp_core/lp_core_basic_tests/main/lp_core/test_main_halt.c @@ -0,0 +1,20 @@ +/* + * SPDX-FileCopyrightText: 2026 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include "ulp_lp_core_utils.h" +#include "hal/lp_core_ll.h" + +int main(void) +{ + // Wait for 1 second to ensure the HP Core enters deep sleep + ulp_lp_core_delay_us(1000000); + + ulp_lp_core_wakeup_main_processor(); + /* Disable wake-up source and put lp core to sleep */ + lp_core_ll_set_wakeup_source(0); + ulp_lp_core_halt(); +} diff --git a/components/ulp/test_apps/lp_core/lp_core_basic_tests/main/lp_core/test_shared.h b/components/ulp/test_apps/lp_core/lp_core_basic_tests/main/lp_core/test_shared.h index d1d07d9327..bb2744406f 100644 --- a/components/ulp/test_apps/lp_core/lp_core_basic_tests/main/lp_core/test_shared.h +++ b/components/ulp/test_apps/lp_core/lp_core_basic_tests/main/lp_core/test_shared.h @@ -22,6 +22,7 @@ typedef enum { LP_CORE_DELAY_US_CALIBRATION_TEST, LP_CORE_DEEP_SLEEP_WAKEUP_SHORT_DELAY_TEST, LP_CORE_DEEP_SLEEP_WAKEUP_LONG_DELAY_TEST, + LP_CORE_HALT_TEST, LP_CORE_LP_UART_WRITE_TEST, LP_CORE_LP_UART_READ_TEST, LP_CORE_LP_UART_MULTI_BYTE_READ_TEST, diff --git a/components/ulp/test_apps/lp_core/lp_core_basic_tests/main/test_lp_core.c b/components/ulp/test_apps/lp_core/lp_core_basic_tests/main/test_lp_core.c index 7250304a03..15ae54832a 100644 --- a/components/ulp/test_apps/lp_core/lp_core_basic_tests/main/test_lp_core.c +++ b/components/ulp/test_apps/lp_core/lp_core_basic_tests/main/test_lp_core.c @@ -40,6 +40,12 @@ #include "hal/lp_core_ll.h" #include "hal/rtc_io_ll.h" #include "driver/rtc_io.h" +#if SOC_LP_CORE_HW_AUTO_CLRWAKEUPCAUSE +#include "rom/rtc.h" +#include "esp_private/esp_pmu.h" +#include "lp_core_test_app_halt.h" +#include "hal/lp_aon_hal.h" +#endif extern const uint8_t lp_core_main_bin_start[] asm("_binary_lp_core_test_app_bin_start"); extern const uint8_t lp_core_main_bin_end[] asm("_binary_lp_core_test_app_bin_end"); @@ -64,6 +70,11 @@ extern const uint8_t lp_core_main_isr_bin_end[] asm("_binary_lp_core_test_app_ extern const uint8_t lp_core_main_exception_bin_start[] asm("_binary_lp_core_test_app_exception_bin_start"); extern const uint8_t lp_core_main_exception_bin_end[] asm("_binary_lp_core_test_app_exception_bin_end"); +#if SOC_LP_CORE_HW_AUTO_CLRWAKEUPCAUSE +extern const uint8_t lp_core_main_halt_bin_start[] asm("_binary_lp_core_test_app_halt_bin_start"); +extern const uint8_t lp_core_main_halt_bin_end[] asm("_binary_lp_core_test_app_halt_bin_end"); +#endif + static void load_and_start_lp_core_firmware(ulp_lp_core_cfg_t* cfg, const uint8_t* firmware_start, const uint8_t* firmware_end) { TEST_ASSERT(ulp_lp_core_load_binary(firmware_start, @@ -648,4 +659,43 @@ static void check_reset_reason_ulp_trap_wakeup(void) TEST_CASE_MULTIPLE_STAGES("LP-core exception can wakeup main cpu", "[ulp]", lp_core_prep_exception_wakeup, check_reset_reason_ulp_trap_wakeup); + +#if SOC_LP_CORE_HW_AUTO_CLRWAKEUPCAUSE +static void do_ulp_wakeup_with_lp_timer_deepsleep_and_halt(void) +{ + /* Load ULP firmware and start the coprocessor */ + ulp_lp_core_cfg_t cfg = { + .wakeup_source = ULP_LP_CORE_WAKEUP_SOURCE_LP_TIMER, + .lp_timer_sleep_duration_us = 1000000, // 1 second +#if ESP_ROM_HAS_LP_ROM + /* ROM Boot takes quite a bit longer, which skews the numbers of wake-ups. skip rom boot to keep the calculation simple */ + .skip_lp_rom_boot = true, +#endif + }; + + load_and_start_lp_core_firmware(&cfg, lp_core_main_halt_bin_start, lp_core_main_halt_bin_end); + + /* Setup wakeup triggers */ + TEST_ASSERT(esp_sleep_enable_ulp_wakeup() == ESP_OK); + + /* Enter Deep Sleep */ + esp_deep_sleep_start(); + + UNITY_TEST_FAIL(__LINE__, "Should not get here!"); +} + +static void check_hp_core_wakeup_cause_saved(void) +{ + uint32_t lp_core_wakeup_cause_status0 = lp_aon_hal_load_wakeup_cause(); + TEST_ASSERT_EQUAL(RTC_LP_CORE_TRIG_EN, lp_core_wakeup_cause_status0 & RTC_LP_CORE_TRIG_EN); + TEST_ASSERT_EQUAL(BIT(ESP_SLEEP_WAKEUP_ULP), esp_sleep_get_wakeup_causes() & BIT(ESP_SLEEP_WAKEUP_ULP)); + + clear_test_cmds(); +} + +TEST_CASE_MULTIPLE_STAGES("HP core wakeup causes are saved after LP core halt", "[ulp]", + do_ulp_wakeup_with_lp_timer_deepsleep_and_halt, + check_hp_core_wakeup_cause_saved); +#endif //SOC_LP_CORE_HW_AUTO_CLRWAKEUPCAUSE + #endif //SOC_DEEP_SLEEP_SUPPORTED