change(ulp): add HP Core wakeup causes save test cases

This commit is contained in:
hebinglin
2026-03-16 16:09:43 +08:00
parent 0603e0eb23
commit b8e0ee431c
6 changed files with 87 additions and 2 deletions
@@ -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]
*************************************************************************************
*/
@@ -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()
@@ -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");
}
@@ -0,0 +1,20 @@
/*
* SPDX-FileCopyrightText: 2026 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#include <stdint.h>
#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();
}
@@ -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,
@@ -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