Merge branch 'feat/new_api_to_get_all_wakeup_causes' into 'master'

feat: add new api to get multiple wakeup causes

Closes PM-472

See merge request espressif/esp-idf!40139
This commit is contained in:
Wu Zheng Hui
2025-07-02 17:36:30 +08:00
41 changed files with 406 additions and 319 deletions

View File

@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2022-2024 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2022-2025 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
@@ -1935,32 +1935,29 @@ static void test_deep_sleep_init(void)
gettimeofday(&now, NULL);
int sleep_time_ms = (now.tv_sec - sleep_enter_time.tv_sec) * 1000 + (now.tv_usec - sleep_enter_time.tv_usec) / 1000;
printf("RTC_CNTL_SLP_WAKEUP_CAUSE_REG %x\n", REG_READ(RTC_CNTL_SLP_WAKEUP_CAUSE_REG));
switch (esp_sleep_get_wakeup_cause()) {
case ESP_SLEEP_WAKEUP_EXT1: {
uint64_t wakeup_pin_mask = esp_sleep_get_ext1_wakeup_status();
if (wakeup_pin_mask != 0) {
int pin = __builtin_ffsll(wakeup_pin_mask) - 1;
printf("Wake up from GPIO %"PRIu32"\n", pin);
} else {
printf("Wake up from GPIO\n");
}
break;
}
case ESP_SLEEP_WAKEUP_TIMER: {
printf("Wake up from timer. Time spent in deep sleep: %"PRIu32"ms\n", sleep_time_ms);
break;
}
case ESP_SLEEP_WAKEUP_TOUCHPAD: {
printf("Wake up from touch on pad %"PRIu32"\n", esp_sleep_get_touchpad_wakeup_status());
break;
}
case ESP_SLEEP_WAKEUP_UNDEFINED:
default: {
uint32_t wakeup_causes = esp_sleep_get_wakeup_causes();
if (wakeup_causes & BIT(ESP_SLEEP_WAKEUP_UNDEFINED)) {
printf("Not a deep sleep reset\n");
ESP_LOGI(TAG, "*********** touch sleep pad wakeup test ********************");
/* Sleep pad should be init once. */
test_touch_sleep_pad_interrupt_wakeup_deep_sleep(touch_list[0]);
}
} else {
if (wakeup_causes & BIT(ESP_SLEEP_WAKEUP_EXT1)) {
uint64_t wakeup_pin_mask = esp_sleep_get_ext1_wakeup_status();
if (wakeup_pin_mask != 0) {
int pin = __builtin_ffsll(wakeup_pin_mask) - 1;
printf("Wake up from GPIO %"PRIu32"\n", pin);
} else {
printf("Wake up from GPIO\n");
}
}
if (wakeup_causes & BIT(ESP_SLEEP_WAKEUP_TIMER)) {
printf("Wake up from timer. Time spent in deep sleep: %"PRIu32"ms\n", sleep_time_ms);
}
if (wakeup_causes & BIT(ESP_SLEEP_WAKEUP_TOUCHPAD)) {
printf("Wake up from touch on pad %"PRIu32"\n", esp_sleep_get_touchpad_wakeup_status());
}
}
vTaskDelay(100 * SYS_DELAY_TIME_MOM / portTICK_PERIOD_MS);

View File

@@ -880,7 +880,7 @@ TEST_CASE("GPIO_light_sleep_wake_up_test", "[gpio][ignore]")
vTaskDelay(1000 / portTICK_PERIOD_MS);
esp_light_sleep_start();
printf("Waked up from light sleep\n");
TEST_ASSERT(esp_sleep_get_wakeup_cause() == ESP_SLEEP_WAKEUP_GPIO);
TEST_ASSERT(esp_sleep_get_wakeup_causes() & BIT(ESP_SLEEP_WAKEUP_GPIO));
}
#endif

View File

@@ -199,16 +199,13 @@ static void enter_sleep_and_send_respond(void)
printf("sleep duration: %lld\n", t_after_us - t_before_us);
/* Determine the reason for uart wakeup */
switch (esp_sleep_get_wakeup_cause()) {
case ESP_SLEEP_WAKEUP_UART:
if (esp_sleep_get_wakeup_causes() & (BIT(ESP_SLEEP_WAKEUP_UART + SLAVE_UART_NUM))) {
/* Hang-up for a while to switch and execute the uart task
* Otherwise the chip may fall sleep again before running uart task */
* Otherwise the chip may fall sleep again before running uart task */
vTaskDelay(1);
uart_write_bytes(SLAVE_UART_NUM, "Wakeup OK!", 11);
break;
default:
} else {
uart_write_bytes(SLAVE_UART_NUM, "Wakeup failed!", 15);
break;
}
/* Wait for uart write finish */

View File

@@ -105,21 +105,23 @@ typedef enum {
* @brief Sleep wakeup cause
*/
typedef enum {
ESP_SLEEP_WAKEUP_UNDEFINED, //!< In case of deep sleep, reset was not caused by exit from deep sleep
ESP_SLEEP_WAKEUP_ALL, //!< Not a wakeup cause, used to disable all wakeup sources with esp_sleep_disable_wakeup_source
ESP_SLEEP_WAKEUP_EXT0, //!< Wakeup caused by external signal using RTC_IO
ESP_SLEEP_WAKEUP_EXT1, //!< Wakeup caused by external signal using RTC_CNTL
ESP_SLEEP_WAKEUP_TIMER, //!< Wakeup caused by timer
ESP_SLEEP_WAKEUP_TOUCHPAD, //!< Wakeup caused by touchpad
ESP_SLEEP_WAKEUP_ULP, //!< Wakeup caused by ULP program
ESP_SLEEP_WAKEUP_GPIO, //!< Wakeup caused by GPIO (light sleep only on ESP32, S2 and S3)
ESP_SLEEP_WAKEUP_UART, //!< Wakeup caused by UART (light sleep only)
ESP_SLEEP_WAKEUP_UNDEFINED, //!< In case of deep sleep, reset was not caused by exit from deep sleep
ESP_SLEEP_WAKEUP_ALL, //!< Not a wakeup cause, used to disable all wakeup sources with esp_sleep_disable_wakeup_source
ESP_SLEEP_WAKEUP_EXT0, //!< Wakeup caused by external signal using RTC_IO
ESP_SLEEP_WAKEUP_EXT1, //!< Wakeup caused by external signal using RTC_CNTL
ESP_SLEEP_WAKEUP_TIMER, //!< Wakeup caused by timer
ESP_SLEEP_WAKEUP_TOUCHPAD, //!< Wakeup caused by touchpad
ESP_SLEEP_WAKEUP_ULP, //!< Wakeup caused by ULP program
ESP_SLEEP_WAKEUP_GPIO, //!< Wakeup caused by GPIO (light sleep only on ESP32, S2 and S3)
ESP_SLEEP_WAKEUP_UART, //!< Wakeup caused by UART0 (light sleep only)
ESP_SLEEP_WAKEUP_UART1, //!< Wakeup caused by UART1 (light sleep only)
ESP_SLEEP_WAKEUP_UART2, //!< Wakeup caused by UART2 (light sleep only)
ESP_SLEEP_WAKEUP_WIFI, //!< Wakeup caused by WIFI (light sleep only)
ESP_SLEEP_WAKEUP_COCPU, //!< Wakeup caused by COCPU int
ESP_SLEEP_WAKEUP_COCPU_TRAP_TRIG, //!< Wakeup caused by COCPU crash
ESP_SLEEP_WAKEUP_BT, //!< Wakeup caused by BT (light sleep only)
ESP_SLEEP_WAKEUP_VAD, //!< Wakeup caused by VAD
ESP_SLEEP_WAKEUP_VBAT_UNDER_VOLT, //!< Wakeup caused by VDD_BAT under voltage.
ESP_SLEEP_WAKEUP_BT, //!< Wakeup caused by BT (light sleep only)
ESP_SLEEP_WAKEUP_VAD, //!< Wakeup caused by VAD
ESP_SLEEP_WAKEUP_VBAT_UNDER_VOLT, //!< Wakeup caused by VDD_BAT under voltage.
} esp_sleep_source_t;
/**
@@ -691,10 +693,20 @@ void esp_deep_sleep_deregister_hook(esp_deep_sleep_cb_t old_dslp_cb);
/**
* @brief Get the wakeup source which caused wakeup from sleep
*
* @note !!! This API will only return one wakeup source. If multiple wakeup sources
* wake up at the same time, the wakeup source information may be lost.
*
* @return cause of wake up from last sleep (deep sleep or light sleep)
*/
esp_sleep_wakeup_cause_t esp_sleep_get_wakeup_cause(void);
esp_sleep_wakeup_cause_t esp_sleep_get_wakeup_cause(void)
__attribute__((deprecated("use esp_sleep_get_wakeup_causes instead")));
/**
* @brief Get all wakeup sources bitmap which caused wakeup from sleep.
*
* @return The bitmap of the wakeup sources of the last wakeup from sleep. (deep sleep or light sleep)
*/
uint32_t esp_sleep_get_wakeup_causes(void);
/**
* @brief Default stub to run on wake from deep sleep.

View File

@@ -1866,7 +1866,7 @@ esp_err_t esp_sleep_enable_touchpad_wakeup(void)
int esp_sleep_get_touchpad_wakeup_status(void)
{
if (esp_sleep_get_wakeup_cause() != ESP_SLEEP_WAKEUP_TOUCHPAD) {
if (!(esp_sleep_get_wakeup_causes() & BIT(ESP_SLEEP_WAKEUP_TOUCHPAD))) {
return -1;
}
uint32_t chan_num;
@@ -2091,7 +2091,7 @@ static void ext1_wakeup_prepare(void)
uint64_t esp_sleep_get_ext1_wakeup_status(void)
{
if (esp_sleep_get_wakeup_cause() != ESP_SLEEP_WAKEUP_EXT1) {
if (!(esp_sleep_get_wakeup_causes() & BIT(ESP_SLEEP_WAKEUP_EXT1))) {
return 0;
}
uint32_t status = rtc_hal_ext1_get_wakeup_status();
@@ -2115,7 +2115,7 @@ uint64_t esp_sleep_get_ext1_wakeup_status(void)
#if SOC_GPIO_SUPPORT_DEEPSLEEP_WAKEUP && SOC_DEEP_SLEEP_SUPPORTED
uint64_t esp_sleep_get_gpio_wakeup_status(void)
{
if (esp_sleep_get_wakeup_cause() != ESP_SLEEP_WAKEUP_GPIO) {
if (!(esp_sleep_get_wakeup_causes() & BIT(ESP_SLEEP_WAKEUP_GPIO))) {
return 0;
}
return rtc_hal_gpio_get_wakeup_status();
@@ -2350,6 +2350,97 @@ esp_sleep_wakeup_cause_t esp_sleep_get_wakeup_cause(void)
}
}
uint32_t esp_sleep_get_wakeup_causes(void)
{
uint32_t wakeup_cause = 0;
if (esp_rom_get_reset_reason(0) != RESET_REASON_CORE_DEEP_SLEEP && !s_light_sleep_wakeup) {
wakeup_cause |= BIT(ESP_SLEEP_WAKEUP_UNDEFINED);
return wakeup_cause;
}
#if SOC_PMU_SUPPORTED
uint32_t wakeup_cause_raw = pmu_ll_hp_get_wakeup_cause(&PMU);
#else
uint32_t wakeup_cause_raw = rtc_cntl_ll_get_wakeup_cause();
#endif
if (wakeup_cause_raw & RTC_TIMER_TRIG_EN) {
wakeup_cause |= BIT(ESP_SLEEP_WAKEUP_TIMER);
}
if (wakeup_cause_raw & RTC_GPIO_TRIG_EN) {
wakeup_cause |= BIT(ESP_SLEEP_WAKEUP_GPIO);
}
if (wakeup_cause_raw & RTC_UART0_TRIG_EN) {
wakeup_cause |= BIT(ESP_SLEEP_WAKEUP_UART);
}
if (wakeup_cause_raw & RTC_UART1_TRIG_EN) {
wakeup_cause |= BIT(ESP_SLEEP_WAKEUP_UART1);
}
#if SOC_PMU_SUPPORTED && (SOC_UART_HP_NUM > 2)
if (wakeup_cause_raw & RTC_UART2_TRIG_EN) {
wakeup_cause |= BIT(ESP_SLEEP_WAKEUP_UART2);
}
#endif
#if SOC_PM_SUPPORT_EXT0_WAKEUP
if (wakeup_cause_raw & RTC_EXT0_TRIG_EN) {
wakeup_cause |= BIT(ESP_SLEEP_WAKEUP_EXT0);
}
#endif
#if SOC_PM_SUPPORT_EXT1_WAKEUP
if (wakeup_cause_raw & RTC_EXT1_TRIG_EN) {
wakeup_cause |= BIT(ESP_SLEEP_WAKEUP_EXT1);
}
#endif
#if SOC_PM_SUPPORT_TOUCH_SENSOR_WAKEUP
if (wakeup_cause_raw & RTC_TOUCH_TRIG_EN) {
wakeup_cause |= BIT(ESP_SLEEP_WAKEUP_TOUCHPAD);
}
#endif
#if SOC_ULP_FSM_SUPPORTED
if (wakeup_cause_raw & RTC_ULP_TRIG_EN) {
wakeup_cause |= BIT(ESP_SLEEP_WAKEUP_ULP);
}
#endif
#if SOC_PM_SUPPORT_WIFI_WAKEUP
if (wakeup_cause_raw & RTC_WIFI_TRIG_EN) {
wakeup_cause |= BIT(ESP_SLEEP_WAKEUP_WIFI);
}
#endif
#if SOC_PM_SUPPORT_BT_WAKEUP
if (wakeup_cause_raw & RTC_BT_TRIG_EN) {
wakeup_cause |= BIT(ESP_SLEEP_WAKEUP_BT);
}
#endif
#if SOC_RISCV_COPROC_SUPPORTED
if (wakeup_cause_raw & RTC_COCPU_TRIG_EN) {
wakeup_cause |= BIT(ESP_SLEEP_WAKEUP_ULP);
}
if (wakeup_cause_raw & RTC_COCPU_TRAP_TRIG_EN) {
wakeup_cause |= BIT(ESP_SLEEP_WAKEUP_COCPU_TRAP_TRIG);
}
#endif
#if SOC_LP_CORE_SUPPORTED
if (wakeup_cause_raw & RTC_LP_CORE_TRIG_EN) {
wakeup_cause |= BIT(ESP_SLEEP_WAKEUP_ULP);
}
#endif
#if SOC_LP_VAD_SUPPORTED
if (wakeup_cause_raw & RTC_LP_VAD_TRIG_EN) {
wakeup_cause |= BIT(ESP_SLEEP_WAKEUP_VAD);
}
#endif
#if SOC_VBAT_SUPPORTED
if (wakeup_cause_raw & RTC_VBAT_UNDER_VOLT_TRIG_EN) {
wakeup_cause |= BIT(ESP_SLEEP_WAKEUP_VBAT_UNDER_VOLT);
}
#endif
if (wakeup_cause == 0) {
wakeup_cause |= BIT(ESP_SLEEP_WAKEUP_UNDEFINED);
}
return wakeup_cause;
}
esp_err_t esp_sleep_pd_config(esp_sleep_pd_domain_t domain, esp_sleep_pd_option_t option)
{
if (domain >= ESP_PD_DOMAIN_MAX || option > ESP_PD_OPTION_AUTO) {

View File

@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2021-2025 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
@@ -59,17 +59,7 @@ static void test_lightsleep(bool force_rtc_periph)
/* Enter sleep mode */
esp_light_sleep_start();
/* Determine wake up reason */
const char* wakeup_reason;
switch (esp_sleep_get_wakeup_cause()) {
case ESP_SLEEP_WAKEUP_TIMER:
wakeup_reason = "timer";
break;
default:
wakeup_reason = "other";
break;
}
printf("Returned from light sleep, reason: %s\n", wakeup_reason);
printf("Returned from light sleep, reason: %s\n", (esp_sleep_get_wakeup_causes() & BIT(ESP_SLEEP_WAKEUP_TIMER)) ? "timer" : "other");
vTaskDelay(1000/portTICK_PERIOD_MS);
}
}

View File

@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2021-2024 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2021-2025 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
@@ -91,18 +91,7 @@ static void test_lightsleep(void)
/* Enter sleep mode */
esp_light_sleep_start();
/* Determine wake up reason */
const char* wakeup_reason;
switch (esp_sleep_get_wakeup_cause()) {
case ESP_SLEEP_WAKEUP_TIMER:
wakeup_reason = "timer";
break;
default:
wakeup_reason = "other";
break;
}
printf("Returned from light sleep, reason: %s\n", wakeup_reason);
printf("Returned from light sleep, reason: %s\n", (esp_sleep_get_wakeup_causes() & BIT(ESP_SLEEP_WAKEUP_TIMER)) ? "timer" : "other");
vTaskDelay(1000/portTICK_PERIOD_MS);
}

View File

@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2021-2024 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2021-2025 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Unlicense OR CC0-1.0
*/
@@ -142,19 +142,7 @@ static void s_lp_vad_config(void)
/* Enter sleep mode */
esp_light_sleep_start();
/* Determine wake up reason */
const char* wakeup_reason;
switch (esp_sleep_get_wakeup_cause()) {
case ESP_SLEEP_WAKEUP_VAD:
wakeup_reason = "vad";
break;
default:
wakeup_reason = "other";
TEST_ASSERT(false);
break;
}
ESP_LOGI(TAG, "wakeup, reason: %s", wakeup_reason);
ESP_LOGI(TAG, "wakeup, reason: %s", (esp_sleep_get_wakeup_causes() & BIT(ESP_SLEEP_WAKEUP_VAD)) ? "vad" : "other");
}
TEST_CASE_MULTIPLE_DEVICES("test LP VAD wakeup", "[vad][ignore][manual]", s_hp_i2s_config, s_lp_vad_config);

View File

@@ -362,8 +362,13 @@ static int process_get_wakeup_cause(int argc, char **argv)
return 1;
}
switch (esp_sleep_get_wakeup_cause()) {
case ESP_SLEEP_WAKEUP_EXT1: {
uint32_t causes = esp_sleep_get_wakeup_causes();
if (causes & BIT(ESP_SLEEP_WAKEUP_UNDEFINED)) {
printf("Wakeup cause err\n");
return 0;
}
if (causes & BIT(ESP_SLEEP_WAKEUP_EXT1)) {
#if SOC_PM_SUPPORT_EXT1_WAKEUP && SOC_RTCIO_PIN_COUNT > 0
uint64_t wakeup_pin_mask = esp_sleep_get_ext1_wakeup_status();
if (wakeup_pin_mask != 0) {
@@ -374,9 +379,9 @@ static int process_get_wakeup_cause(int argc, char **argv)
{
printf("Wake up from EXT1 triggered, but unknown wake-up IO\n");
}
break;
}
case ESP_SLEEP_WAKEUP_GPIO: {
if (causes & BIT(ESP_SLEEP_WAKEUP_GPIO)) {
if (esp_reset_reason() == ESP_RST_DEEPSLEEP) {
#if SOC_GPIO_SUPPORT_DEEPSLEEP_WAKEUP
uint64_t wakeup_pin_mask = esp_sleep_get_gpio_wakeup_status();
@@ -409,11 +414,6 @@ static int process_get_wakeup_cause(int argc, char **argv)
gpio_ll_clear_intr_status(&GPIO, 0xFFFFFFFF);
gpio_ll_clear_intr_status_high(&GPIO, 0xFFFFFFFF);
}
break;
}
default: {
printf("Wakeup cause err\n");
}
}
return 0;
}

View File

@@ -338,8 +338,7 @@ bool te_is_touch_dsleep_wakeup(void)
if (reset_reason != RESET_REASON_CORE_DEEP_SLEEP) {
return false;
}
esp_sleep_wakeup_cause_t wakeup_reason = esp_sleep_get_wakeup_cause();
return wakeup_reason == ESP_SLEEP_WAKEUP_TOUCHPAD;
return !!(esp_sleep_get_wakeup_causes() & BIT(ESP_SLEEP_WAKEUP_TOUCHPAD));
}
touch_pad_t te_get_sleep_channel(void)

View File

@@ -156,7 +156,7 @@ static void do_ulp_wakeup_deepsleep(lp_core_test_commands_t ulp_cmd)
static void check_reset_reason_ulp_wakeup(void)
{
TEST_ASSERT_EQUAL(ESP_SLEEP_WAKEUP_ULP, esp_sleep_get_wakeup_cause());
TEST_ASSERT_EQUAL(BIT(ESP_SLEEP_WAKEUP_ULP), esp_sleep_get_wakeup_causes() & BIT(ESP_SLEEP_WAKEUP_ULP));
}
static void do_ulp_wakeup_after_short_delay_deepsleep(void)
@@ -213,7 +213,7 @@ static void check_reset_reason_and_sleep_duration(void)
struct timeval tv_stop = {};
gettimeofday(&tv_stop, NULL);
TEST_ASSERT_EQUAL(ESP_SLEEP_WAKEUP_ULP, esp_sleep_get_wakeup_cause());
TEST_ASSERT_EQUAL(BIT(ESP_SLEEP_WAKEUP_ULP), esp_sleep_get_wakeup_causes() & BIT(ESP_SLEEP_WAKEUP_ULP));
int64_t sleep_duration = (tv_stop.tv_sec - tv_start.tv_sec) * 1000 + (tv_stop.tv_usec - tv_start.tv_usec) / 1000;
int64_t expected_sleep_duration_ms = ulp_counter_wakeup_limit * LP_TIMER_TEST_SLEEP_DURATION_US / 1000;

View File

@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2010-2024 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2010-2025 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
@@ -193,8 +193,8 @@ TEST_CASE("ULP FSM light-sleep wakeup test", "[ulp]")
TEST_ASSERT(esp_light_sleep_start() == ESP_OK);
/* Wait for wakeup from ULP FSM Coprocessor */
printf("cause %d\r\n", esp_sleep_get_wakeup_cause());
TEST_ASSERT(esp_sleep_get_wakeup_cause() == ESP_SLEEP_WAKEUP_ULP);
printf("causes %lx\r\n", esp_sleep_get_wakeup_causes());
TEST_ASSERT(esp_sleep_get_wakeup_causes() & BIT(ESP_SLEEP_WAKEUP_ULP));
}
static void ulp_fsm_deepsleep_wakeup_test(void)
@@ -239,8 +239,8 @@ static void ulp_fsm_deepsleep_wakeup_test(void)
static void check_sleep_reset(void)
{
TEST_ASSERT_EQUAL(ESP_RST_DEEPSLEEP, esp_reset_reason());
esp_sleep_wakeup_cause_t cause = esp_sleep_get_wakeup_cause();
TEST_ASSERT_EQUAL(ESP_SLEEP_WAKEUP_ULP, cause);
uint32_t causes = esp_sleep_get_wakeup_causes();
TEST_ASSERT_EQUAL(BIT(ESP_SLEEP_WAKEUP_ULP), causes & BIT(ESP_SLEEP_WAKEUP_ULP));
}
TEST_CASE_MULTIPLE_STAGES("ULP FSM deep-sleep wakeup test", "[deepsleep][reset=DEEPSLEEP_RESET]",

View File

@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2010-2024 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2010-2025 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
@@ -196,7 +196,7 @@ TEST_CASE("ULP-RISC-V can be loaded with and run multiple firmwares", "[ulp]")
TEST_ASSERT(ulp_riscv_is_running(&ulp_riscv_counter));
}
TEST_CASE("ULP-RISC-V can be reloaded with a good fimware after a crash", "[ulp]")
TEST_CASE("ULP-RISC-V can be reloaded with a good firmware after a crash", "[ulp]")
{
/* Load ULP RISC-V firmware and start the ULP RISC-V Coprocessor */
load_and_start_ulp_firmware(ulp_main_bin_start, ulp_main_bin_length);
@@ -218,8 +218,7 @@ TEST_CASE("ULP-RISC-V can be reloaded with a good fimware after a crash", "[ulp]
esp_light_sleep_start();
/* Verify that main CPU wakes up by a COCPU trap signal trigger */
esp_sleep_wakeup_cause_t cause = esp_sleep_get_wakeup_cause();
TEST_ASSERT(cause == ESP_SLEEP_WAKEUP_COCPU_TRAP_TRIG);
TEST_ASSERT(esp_sleep_get_wakeup_causes() & BIT(ESP_SLEEP_WAKEUP_COCPU_TRAP_TRIG));
printf("Resetting the ULP\n");
ulp_riscv_reset();
@@ -312,7 +311,7 @@ static void do_ulp_wakeup_deepsleep(riscv_test_commands_t ulp_cmd, bool rtc_peri
static void check_reset_reason_ulp_wakeup(void)
{
TEST_ASSERT_EQUAL(ESP_SLEEP_WAKEUP_ULP, esp_sleep_get_wakeup_cause());
TEST_ASSERT_EQUAL(BIT(ESP_SLEEP_WAKEUP_ULP), esp_sleep_get_wakeup_causes() & BIT(ESP_SLEEP_WAKEUP_ULP));
}
static void do_ulp_wakeup_after_long_delay_deepsleep(void)

View File

@@ -8,3 +8,32 @@ Xtensa
The Xtensa special register header files have been updated to use a new naming convention. The old ``specreg.h`` header files are now deprecated and will be removed in a future release.
The register names have been updated to use the ``XT_REG_`` prefix. Please use the new ``xt_specreg.h`` file instead.
Power Management
----------------
In previous versions of ESP-IDF, the API :cpp:func:`esp_sleep_get_wakeup_cause` was used to retrieve the wakeup reason after the chip exited sleep. However, this function only returns one wakeup source, even if multiple sources were triggered simultaneously, which may cause users to miss other active wakeup events.
Since ESP-IDF v6.0, a new API :cpp:func:`esp_sleep_get_wakeup_causes` has been introduced. This function returns a bitmap representing all wakeup sources that caused the chip to exit sleep. Each bit corresponds to a value in the :cpp:type:`esp_sleep_wakeup_cause_t` enum (e.g., ESP_SLEEP_WAKEUP_TIMER, ESP_SLEEP_WAKEUP_EXT1, etc.). Users can check each wakeup source using bitwise operations.
The original :cpp:func:`esp_sleep_get_wakeup_cause()` function has been marked as deprecated, and it is recommended to migrate to the new interface. This legacy API may be removed in future versions. Migration can be performed as shown in the example below:
Old Version:
.. code-block:: c
esp_sleep_wakeup_cause_t cause = esp_sleep_get_wakeup_cause();
if (cause == ESP_SLEEP_WAKEUP_EXT1) {
handle_ext1_wakeup();
}
Update to:
.. code-block:: c
uint32_t causes = esp_sleep_get_wakeup_causes();
if (causes & BIT(ESP_SLEEP_WAKEUP_EXT1)) {
handle_ext1_wakeup();
}
if (causes & BIT(ESP_SLEEP_WAKEUP_TIMER)) {
handle_timer_wakeup();
}

View File

@@ -9,3 +9,30 @@ Xtensa
Xtensa 特殊寄存器头文件已更新,使用新的命名约定。旧的 ``specreg.h`` 头文件现已被弃用,并将在未来版本中移除。
寄存器名称已更新为使用 ``XT_REG_`` 前缀。请使用新的 ``xt_specreg.h`` 文件。
电源管理
--------
在旧版本的 ESP-IDF 中,使用 :cpp:func:`esp_sleep_get_wakeup_cause` API 获取芯片从睡眠中唤醒的原因,然而,该函数在多个唤醒源同时激活的情况下,只会返回其中一个唤醒源,可能导致用户遗漏其他同时发生的唤醒条件。
自 v6.0 版本起ESP-IDF 新增 :cpp:func:`esp_sleep_get_wakeup_causes` API此函数返回一个 bitmap表示所有触发唤醒的唤醒源。每一位对应 :cpp:type:`esp_sleep_wakeup_cause_t` 枚举中的一个值(例如 ESP_SLEEP_WAKEUP_TIMER、ESP_SLEEP_WAKEUP_EXT1 等),用户可以通过按位与操作判断是否被对应源唤醒。
原先的 :cpp:func:`esp_sleep_get_wakeup_cause()` 函数现已标记为 已废弃deprecated建议用户迁移至新接口未来版本中该函数可能会被移除。用户可按以下示例进行迁移
旧代码:
.. code-block:: c
esp_sleep_wakeup_cause_t cause = esp_sleep_get_wakeup_cause();
if (cause == ESP_SLEEP_WAKEUP_EXT1) {
handle_ext1_wakeup();
}
现在需要修改成:
.. code-block:: c
uint32_t causes = esp_sleep_get_wakeup_causes();
if (causes & BIT(ESP_SLEEP_WAKEUP_EXT1)) {
handle_ext1_wakeup();
}
if (causes & BIT(ESP_SLEEP_WAKEUP_TIMER)) {
handle_timer_wakeup();
}

View File

@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2015-2024 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2015-2025 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
@@ -313,23 +313,22 @@ static int light_sleep(int argc, char **argv)
fflush(stdout);
uart_wait_tx_idle_polling(CONFIG_ESP_CONSOLE_UART_NUM);
esp_light_sleep_start();
esp_sleep_wakeup_cause_t cause = esp_sleep_get_wakeup_cause();
const char *cause_str;
switch (cause) {
case ESP_SLEEP_WAKEUP_GPIO:
cause_str = "GPIO";
break;
case ESP_SLEEP_WAKEUP_UART:
cause_str = "UART";
break;
case ESP_SLEEP_WAKEUP_TIMER:
cause_str = "timer";
break;
default:
cause_str = "unknown";
printf("%d\n", cause);
uint32_t causes = esp_sleep_get_wakeup_causes();
if (causes & BIT(ESP_SLEEP_WAKEUP_UNDEFINED)) {
ESP_LOGI(TAG, "Woke up from: unknown");
printf("%lx\n", causes);
return 0;
}
if (causes & BIT(ESP_SLEEP_WAKEUP_GPIO)) {
ESP_LOGI(TAG, "Woke up from: GPIO");
}
if (causes & BIT(ESP_SLEEP_WAKEUP_UART)) {
ESP_LOGI(TAG, "Woke up from: UART");
}
if (causes & BIT(ESP_SLEEP_WAKEUP_TIMER)) {
ESP_LOGI(TAG, "Woke up from: timer");
}
ESP_LOGI(TAG, "Woke up from: %s", cause_str);
return 0;
}

View File

@@ -24,16 +24,20 @@ void app_main(void)
ESP_ERROR_CHECK(esp_pm_configure(&pm_config));
#endif
if (esp_sleep_get_wakeup_cause() == ESP_SLEEP_WAKEUP_VBAT_UNDER_VOLT) {
#if CONFIG_ESP_VBAT_USE_RECHARGEABLE_BATTERY
printf("Wake up from VBAT low power\n");
#else
printf("Wake up from VBAT brownout\n");
#endif
} else if (esp_sleep_get_wakeup_cause() == ESP_SLEEP_WAKEUP_TIMER) {
printf("Wake up from Timer\n");
} else {
uint32_t causes = esp_sleep_get_wakeup_causes();
if (causes & BIT(ESP_SLEEP_WAKEUP_UNDEFINED)) {
printf("Not a deep sleep reset\n");
} else {
if (causes & BIT(ESP_SLEEP_WAKEUP_VBAT_UNDER_VOLT)) {
#if CONFIG_ESP_VBAT_USE_RECHARGEABLE_BATTERY
printf("Wake up from VBAT low power\n");
#else
printf("Wake up from VBAT brownout\n");
#endif
}
if (causes & BIT(ESP_SLEEP_WAKEUP_TIMER)) {
printf("Wake up from Timer\n");
}
}
esp_err_t sleep_result;

View File

@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2023-2025 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: CC0-1.0
*
@@ -115,20 +115,17 @@ static void ot_deep_sleep_init(void)
struct timeval now;
gettimeofday(&now, NULL);
int sleep_time_ms = (now.tv_sec - s_sleep_enter_time.tv_sec) * 1000 + (now.tv_usec - s_sleep_enter_time.tv_usec) / 1000;
esp_sleep_wakeup_cause_t wake_up_cause = esp_sleep_get_wakeup_cause();
switch (wake_up_cause) {
case ESP_SLEEP_WAKEUP_TIMER: {
ESP_LOGI(TAG, "Wake up from timer. Time spent in deep sleep and boot: %dms", sleep_time_ms);
break;
}
case ESP_SLEEP_WAKEUP_EXT1: {
ESP_LOGI(TAG, "Wake up from GPIO. Time spent in deep sleep and boot: %dms", sleep_time_ms);
break;
}
case ESP_SLEEP_WAKEUP_UNDEFINED:
default:
uint32_t wake_up_causes = esp_sleep_get_wakeup_causes();
if (wake_up_causes & BIT(ESP_SLEEP_WAKEUP_UNDEFINED)) {
ESP_LOGI(TAG, "Not a deep sleep reset");
break;
} else {
if(wake_up_causes & BIT(ESP_SLEEP_WAKEUP_TIMER)) {
ESP_LOGI(TAG, "Wake up from timer. Time spent in deep sleep and boot: %dms", sleep_time_ms);
}
if(wake_up_causes & BIT(ESP_SLEEP_WAKEUP_EXT1)) {
ESP_LOGI(TAG, "Wake up from GPIO. Time spent in deep sleep and boot: %dms", sleep_time_ms);
}
}
// Set the methods of how to wake up:

View File

@@ -156,7 +156,7 @@ void example_prepare_sleep(void)
/* Enter the light sleep */
esp_light_sleep_start();
/* Keep executing the code after waking up from the light sleep */
if (esp_sleep_get_wakeup_cause() == ESP_SLEEP_WAKEUP_TOUCHPAD) {
if (esp_sleep_get_wakeup_causes() & BIT(ESP_SLEEP_WAKEUP_TOUCHPAD)) {
ESP_LOGI(TAG, "Wake up by touch\n");
} else {
ESP_LOGE(TAG, "Wake up by other source\n");
@@ -180,7 +180,7 @@ void app_main(void)
{
#if CONFIG_EXAMPLE_TOUCH_DEEP_SLEEP_WAKEUP
/* Printing the log if the chip is waken up from deepsleep by the touchpad */
if (esp_sleep_get_wakeup_cause() == ESP_SLEEP_WAKEUP_TOUCHPAD) {
if (esp_sleep_get_wakeup_causes() & BIT(ESP_SLEEP_WAKEUP_TOUCHPAD)) {
ESP_LOGI(TAG, "Wake up by touch\n");
}
#endif // CONFIG_EXAMPLE_TOUCH_DEEP_SLEEP_WAKEUP

View File

@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2023-2024 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2023-2025 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Unlicense OR CC0-1.0
*/
@@ -167,24 +167,22 @@ static int light_sleep(int argc, char **argv)
fflush(stdout);
fsync(fileno(stdout));
esp_light_sleep_start();
esp_sleep_wakeup_cause_t cause = esp_sleep_get_wakeup_cause();
const char *cause_str;
switch (cause) {
case ESP_SLEEP_WAKEUP_GPIO:
cause_str = "GPIO";
break;
case ESP_SLEEP_WAKEUP_UART:
cause_str = "UART";
break;
case ESP_SLEEP_WAKEUP_TIMER:
cause_str = "timer";
break;
default:
cause_str = "unknown";
printf("%d\n", cause);
uint32_t causes = esp_sleep_get_wakeup_causes();
if (causes & BIT(ESP_SLEEP_WAKEUP_UNDEFINED)) {
ESP_LOGI(TAG, "Woke up from: unknown");
printf("%lx\n", causes);
return 0;
}
if (causes & BIT(ESP_SLEEP_WAKEUP_GPIO)) {
ESP_LOGI(TAG, "Woke up from: GPIO");
}
if (causes & BIT(ESP_SLEEP_WAKEUP_UART)) {
ESP_LOGI(TAG, "Woke up from: UART");
}
if (causes & BIT(ESP_SLEEP_WAKEUP_TIMER)) {
ESP_LOGI(TAG, "Woke up from: timer");
}
ESP_LOGI(TAG, "Woke up from: %s", cause_str);
return 0;
}

View File

@@ -59,14 +59,15 @@ static void deep_sleep_task(void *args)
gettimeofday(&now, NULL);
int sleep_time_ms = (now.tv_sec - sleep_enter_time.tv_sec) * 1000 + (now.tv_usec - sleep_enter_time.tv_usec) / 1000;
switch (esp_sleep_get_wakeup_cause()) {
case ESP_SLEEP_WAKEUP_TIMER: {
uint32_t causes = esp_sleep_get_wakeup_causes();
if (causes & BIT(ESP_SLEEP_WAKEUP_UNDEFINED)) {
printf("Not a deep sleep reset\n");
} else {
if (causes & BIT(ESP_SLEEP_WAKEUP_TIMER)) {
printf("Wake up from timer. Time spent in deep sleep: %dms\n", sleep_time_ms);
break;
}
#if CONFIG_EXAMPLE_GPIO_WAKEUP
case ESP_SLEEP_WAKEUP_GPIO: {
if (causes & BIT(ESP_SLEEP_WAKEUP_GPIO)) {
uint64_t wakeup_pin_mask = esp_sleep_get_gpio_wakeup_status();
if (wakeup_pin_mask != 0) {
int pin = __builtin_ffsll(wakeup_pin_mask) - 1;
@@ -74,19 +75,15 @@ static void deep_sleep_task(void *args)
} else {
printf("Wake up from GPIO\n");
}
break;
}
#endif //CONFIG_EXAMPLE_GPIO_WAKEUP
#if CONFIG_EXAMPLE_EXT0_WAKEUP
case ESP_SLEEP_WAKEUP_EXT0: {
if (causes & BIT(ESP_SLEEP_WAKEUP_EXT0)) {
printf("Wake up from ext0\n");
break;
}
#endif // CONFIG_EXAMPLE_EXT0_WAKEUP
#ifdef CONFIG_EXAMPLE_EXT1_WAKEUP
case ESP_SLEEP_WAKEUP_EXT1: {
if (causes & BIT(ESP_SLEEP_WAKEUP_EXT1)) {
uint64_t wakeup_pin_mask = esp_sleep_get_ext1_wakeup_status();
if (wakeup_pin_mask != 0) {
int pin = __builtin_ffsll(wakeup_pin_mask) - 1;
@@ -94,13 +91,8 @@ static void deep_sleep_task(void *args)
} else {
printf("Wake up from GPIO\n");
}
break;
}
#endif // CONFIG_EXAMPLE_EXT1_WAKEUP
case ESP_SLEEP_WAKEUP_UNDEFINED:
default:
printf("Not a deep sleep reset\n");
}
vTaskDelay(1000 / portTICK_PERIOD_MS);

View File

@@ -26,7 +26,7 @@ void app_main(void)
gettimeofday(&now, NULL);
int sleep_time_ms = (now.tv_sec - sleep_enter_time.tv_sec) * 1000 + (now.tv_usec - sleep_enter_time.tv_usec) / 1000;
if (esp_sleep_get_wakeup_cause() == ESP_SLEEP_WAKEUP_TIMER) {
if (esp_sleep_get_wakeup_causes() & BIT(ESP_SLEEP_WAKEUP_TIMER)) {
printf("Wake up from timer. Time spent in deep sleep: %dms\n", sleep_time_ms);
}

View File

@@ -37,22 +37,18 @@ static void light_sleep_task(void *args)
/* Determine wake up reason */
const char* wakeup_reason;
switch (esp_sleep_get_wakeup_cause()) {
case ESP_SLEEP_WAKEUP_TIMER:
wakeup_reason = "timer";
break;
case ESP_SLEEP_WAKEUP_GPIO:
wakeup_reason = "pin";
break;
case ESP_SLEEP_WAKEUP_UART:
wakeup_reason = "uart";
/* Hang-up for a while to switch and execute the uart task
* Otherwise the chip may fall sleep again before running uart task */
vTaskDelay(1);
break;
default:
wakeup_reason = "other";
break;
uint32_t wakup_causes = esp_sleep_get_wakeup_causes();
if (wakup_causes & BIT(ESP_SLEEP_WAKEUP_TIMER)) {
wakeup_reason = "timer";
} else if (wakup_causes & BIT(ESP_SLEEP_WAKEUP_GPIO)) {
wakeup_reason = "pin";
} else if (wakup_causes & (BIT(ESP_SLEEP_WAKEUP_UART) | BIT(ESP_SLEEP_WAKEUP_UART1) | BIT(ESP_SLEEP_WAKEUP_UART2))) {
wakeup_reason = "uart";
/* Hang-up for a while to switch and execute the uart task
* Otherwise the chip may fall sleep again before running uart task */
vTaskDelay(1);
} else {
wakeup_reason = "other";
}
#if CONFIG_NEWLIB_NANO_FORMAT
/* printf in newlib-nano does not support %ll format, causing example test fail */
@@ -62,7 +58,7 @@ static void light_sleep_task(void *args)
printf("Returned from light sleep, reason: %s, t=%lld ms, slept for %lld ms\n",
wakeup_reason, t_after_us / 1000, (t_after_us - t_before_us) / 1000);
#endif
if (esp_sleep_get_wakeup_cause() == ESP_SLEEP_WAKEUP_GPIO) {
if (wakup_causes & BIT(ESP_SLEEP_WAKEUP_GPIO)) {
/* Waiting for the gpio inactive, or the chip will continuously trigger wakeup*/
example_wait_gpio_inactive();
}

View File

@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2023-2024 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2023-2025 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Unlicense OR CC0-1.0
*/
@@ -43,18 +43,15 @@ void app_main(void)
rtc_gpio_pulldown_dis(WAKEUP_PIN);
rtc_gpio_pullup_dis(WAKEUP_PIN);
esp_sleep_wakeup_cause_t cause = esp_sleep_get_wakeup_cause();
/* not a wakeup from ULP, load the firmware */
if (cause != ESP_SLEEP_WAKEUP_ULP) {
printf("Not a ULP wakeup, initializing it! \n");
init_ulp_program();
}
/* ULP read and detected a change in GPIO_0, prints */
if (cause == ESP_SLEEP_WAKEUP_ULP) {
if (esp_sleep_get_wakeup_causes() & BIT(ESP_SLEEP_WAKEUP_ULP)) {
/* ULP read and detected a change in GPIO_0, prints */
printf("ULP woke up the main CPU! \n");
printf("ULP read changes in GPIO_0 current is: %s \n",
(bool)(ulp_gpio_level_previous == 0) ? "Low" : "High" );
} else {
/* not a wakeup from ULP, load the firmware */
printf("Not a ULP wakeup, initializing it! \n");
init_ulp_program();
}
/* Go back to sleep, only the ULP will run */

View File

@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2024-2025 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Unlicense OR CC0-1.0
*/
@@ -47,14 +47,13 @@ void app_main(void)
printf("ULP will wake up processor after every %d pulses\n", CONFIG_EXAMPLE_PULSE_COUNT_WAKEUP_LIMIT);
esp_sleep_wakeup_cause_t cause = esp_sleep_get_wakeup_cause();
/* not a wakeup from ULP, load the firmware */
if (cause != ESP_SLEEP_WAKEUP_ULP) {
printf("Not a ULP wakeup, initializing it! \n");
init_ulp_program();
} else {
if (esp_sleep_get_wakeup_causes() & BIT(ESP_SLEEP_WAKEUP_ULP)) {
printf("ULP woke up the main CPU!\n");
printf("Pulse count: %"PRIu32"\n", ulp_pulse_count);
} else {
printf("Not a ULP wakeup, initializing it! \n");
init_ulp_program();
}
/* Go back to sleep, only the ULP will run */

View File

@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2024-2025 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Unlicense OR CC0-1.0
*/
@@ -48,18 +48,15 @@ void app_main(void)
wakeup_gpio_init();
esp_sleep_wakeup_cause_t cause = esp_sleep_get_wakeup_cause();
/* not a wakeup from ULP, load the firmware */
if (cause != ESP_SLEEP_WAKEUP_ULP) {
if (esp_sleep_get_wakeup_causes() & BIT(ESP_SLEEP_WAKEUP_ULP)) {
/* ULP read and detected a change in WAKEUP_PIN, prints */
printf("ULP woke up the main CPU! \n");
} else {
/* not a wakeup from ULP, load the firmware */
printf("Not a ULP wakeup, initializing it! \n");
init_ulp_program();
}
/* ULP read and detected a change in WAKEUP_PIN, prints */
if (cause == ESP_SLEEP_WAKEUP_ULP) {
printf("ULP woke up the main CPU! \n");
}
/* Go back to sleep, only the ULP will run */
printf("Entering deep sleep\n\n");

View File

@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2023-2024 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2023-2025 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
@@ -62,9 +62,12 @@ void app_main(void)
*/
vTaskDelay(pdMS_TO_TICKS(1000));
esp_sleep_wakeup_cause_t cause = esp_sleep_get_wakeup_cause();
if (cause != ESP_SLEEP_WAKEUP_ULP) {
printf("Not an LP core wakeup. Cause = %d\n", cause);
uint32_t causes = esp_sleep_get_wakeup_causes();
if (causes & BIT(ESP_SLEEP_WAKEUP_ULP)) {
printf("LP core woke up the main CPU\n");
printf("Lux = %ld\n", ulp_lux);
} else {
printf("Not an LP core wakeup. Causes = %lx\n", causes);
printf("Initializing...\n");
/* Initialize LP_I2C from the main processor */
@@ -72,9 +75,6 @@ void app_main(void)
/* Load LP Core binary and start the coprocessor */
lp_core_init();
} else if (cause == ESP_SLEEP_WAKEUP_ULP) {
printf("LP core woke up the main CPU\n");
printf("Lux = %ld\n", ulp_lux);
}
/* Setup wakeup triggers */

View File

@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2024-2025 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
@@ -78,9 +78,12 @@ void app_main(void)
*/
vTaskDelay(pdMS_TO_TICKS(1000));
esp_sleep_wakeup_cause_t cause = esp_sleep_get_wakeup_cause();
if (cause != ESP_SLEEP_WAKEUP_ULP) {
printf("Not an LP core wakeup. Cause = %d\n", cause);
uint32_t causes = esp_sleep_get_wakeup_causes();
if (esp_sleep_get_wakeup_causes() & BIT(ESP_SLEEP_WAKEUP_ULP)) {
printf("LP core woke up the main CPU\n");
printf("Temperature %.2f degree celsius, humidity %.2f%%RH\n", ulp_temperature / 100.0, ulp_humidity / 1024.0);
} else {
printf("Not an LP core wakeup. Causes = %lx\n", causes);
printf("Initializing...\n");
/* Initialize LP_SPI from the main processor */
@@ -88,9 +91,6 @@ void app_main(void)
/* Load LP Core binary and start the coprocessor */
lp_core_init();
} else if (cause == ESP_SLEEP_WAKEUP_ULP) {
printf("LP core woke up the main CPU\n");
printf("Temperature %.2f degree celsius, humidity %.2f%%RH\n", ulp_temperature / 100.0, ulp_humidity / 1024.0);
}
/* Setup wakeup triggers */

View File

@@ -154,9 +154,9 @@ void app_main(void)
*/
vTaskDelay(pdMS_TO_TICKS(1000));
esp_sleep_wakeup_cause_t cause = esp_sleep_get_wakeup_cause();
uint32_t causes = esp_sleep_get_wakeup_causes();
/* Woke up by LP core, i.e., wake up the main CPU in the LP program */
if (cause == ESP_SLEEP_WAKEUP_ULP) {
if (causes & BIT(ESP_SLEEP_WAKEUP_ULP)) {
printf("LP core woke up the main CPU\n");
// We can access the LP core global variable by adding `ulp_` prefix
uint32_t touch_data = ulp_touch_data;
@@ -169,7 +169,7 @@ void app_main(void)
}
/* Woke up by other source, like power_on */
else {
printf("Not an LP core wakeup. Cause = %d\n", cause);
printf("Not an LP core wakeup. Causes = %lx\n", causes);
printf("Initializing...\n");
/* Initialize Touch sensor from the main processor */

View File

@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2023-2024 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2023-2025 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
@@ -50,9 +50,9 @@ void app_main(void)
*/
vTaskDelay(pdMS_TO_TICKS(1000));
esp_sleep_wakeup_cause_t cause = esp_sleep_get_wakeup_cause();
if (cause != ESP_SLEEP_WAKEUP_ULP) {
printf("Not an LP core wakeup. Cause = %d\n", cause);
uint32_t causes = esp_sleep_get_wakeup_causes();
if (!(causes & BIT(ESP_SLEEP_WAKEUP_ULP))) {
printf("Not an LP core wakeup. Causes = %lx\n", causes);
printf("Initializing...\n");
/* Initialize LP_UART */

View File

@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2023-2024 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2023-2025 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
@@ -51,9 +51,9 @@ void app_main(void)
*/
vTaskDelay(pdMS_TO_TICKS(1000));
esp_sleep_wakeup_cause_t cause = esp_sleep_get_wakeup_cause();
if (cause != ESP_SLEEP_WAKEUP_ULP) {
printf("Not an LP core wakeup. Cause = %d\n", cause);
uint32_t causes = esp_sleep_get_wakeup_causes();
if (!(causes & BIT(ESP_SLEEP_WAKEUP_ULP))) {
printf("Not an LP core wakeup. Causes = %lx\n", causes);
printf("Initializing...\n");
/* Initialize LP_UART */

View File

@@ -42,8 +42,8 @@ void app_main(void)
*/
vTaskDelay(pdMS_TO_TICKS(1000));
esp_sleep_wakeup_cause_t cause = esp_sleep_get_wakeup_cause();
if (cause != ESP_SLEEP_WAKEUP_ULP) {
uint32_t causes = esp_sleep_get_wakeup_causes();
if (!(causes & BIT(ESP_SLEEP_WAKEUP_ULP))) {
printf("Not ULP wakeup, initializing ULP\n");
init_ulp_program();
} else {

View File

@@ -51,8 +51,8 @@ void app_main(void)
*/
vTaskDelay(pdMS_TO_TICKS(1000));
esp_sleep_wakeup_cause_t cause = esp_sleep_get_wakeup_cause();
if (cause != ESP_SLEEP_WAKEUP_ULP) {
uint32_t causes = esp_sleep_get_wakeup_causes();
if (!(causes & BIT(ESP_SLEEP_WAKEUP_ULP))) {
printf("Not ULP wakeup\n");
init_ulp_program();
} else {

View File

@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2022-2024 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2022-2025 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Unlicense OR CC0-1.0
*/
@@ -37,16 +37,16 @@ void app_main(void)
*/
vTaskDelay(pdMS_TO_TICKS(1000));
esp_sleep_wakeup_cause_t cause = esp_sleep_get_wakeup_cause();
uint32_t causes = esp_sleep_get_wakeup_causes();
/* not a wakeup from ULP, load the firmware */
if ((cause != ESP_SLEEP_WAKEUP_ULP) && (cause != ESP_SLEEP_WAKEUP_TIMER)) {
printf("Not a ULP-RISC-V wakeup (cause = %d), initializing it! \n", cause);
if (!(causes & (BIT(ESP_SLEEP_WAKEUP_ULP) | BIT(ESP_SLEEP_WAKEUP_TIMER)))) {
printf("Not a ULP-RISC-V wakeup (causes = %lx), initializing it! \n", causes);
init_ulp_program();
}
/* ULP Risc-V read and detected a temperature above the limit */
if (cause == ESP_SLEEP_WAKEUP_ULP) {
if (causes & BIT(ESP_SLEEP_WAKEUP_ULP)) {
printf("ULP-RISC-V woke up the main CPU\n");
printf("Threshold: high = %"PRIu32"\n", ulp_adc_threshold);
printf("Value = %"PRIu32" was above threshold\n", ulp_wakeup_result);

View File

@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2023-2024 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2023-2025 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Unlicense OR CC0-1.0
*/
@@ -44,15 +44,15 @@ void app_main(void)
*/
vTaskDelay(pdMS_TO_TICKS(1000));
esp_sleep_wakeup_cause_t cause = esp_sleep_get_wakeup_cause();
uint32_t causes = esp_sleep_get_wakeup_causes();
/* not a wakeup from ULP, load the firmware */
if (cause != ESP_SLEEP_WAKEUP_ULP) {
printf("Not a ULP-RISC-V wakeup (cause = %d), initializing it! \n", cause);
if (!(causes & BIT(ESP_SLEEP_WAKEUP_ULP))) {
printf("Not a ULP-RISC-V wakeup (causes = %lx), initializing it! \n", causes);
init_ulp_program();
}
/* ULP Risc-V read and detected a temperature above the limit */
if (cause == ESP_SLEEP_WAKEUP_ULP) {
if (causes & BIT(ESP_SLEEP_WAKEUP_ULP)) {
printf("ULP-RISC-V woke up the main CPU, temperature is above set limit! \n");
printf("ULP-RISC-V read temperature is %f\n", ulp_temp_reg_val / 16.0);
}

View File

@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2023-2024 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2023-2025 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Unlicense OR CC0-1.0
*/
@@ -45,15 +45,15 @@ void app_main(void)
rtc_gpio_pullup_dis(GPIO_NUM_0);
rtc_gpio_hold_en(GPIO_NUM_0);
esp_sleep_wakeup_cause_t cause = esp_sleep_get_wakeup_cause();
uint32_t causes = esp_sleep_get_wakeup_causes();
/* not a wakeup from ULP, load the firmware */
if (cause != ESP_SLEEP_WAKEUP_ULP) {
if (!(causes & BIT(ESP_SLEEP_WAKEUP_ULP))) {
printf("Not a ULP-RISC-V wakeup, initializing it! \n");
init_ulp_program();
}
/* ULP Risc-V read and detected a change in GPIO_0, prints */
if (cause == ESP_SLEEP_WAKEUP_ULP) {
if (causes & BIT(ESP_SLEEP_WAKEUP_ULP)) {
printf("ULP-RISC-V woke up the main CPU! \n");
printf("ULP-RISC-V read changes in GPIO_0 current is: %s \n",
(bool)(ulp_gpio_level_previous == 0) ? "Low" : "High" );

View File

@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2022-2024 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2022-2025 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Unlicense OR CC0-1.0
*/
@@ -49,15 +49,15 @@ void app_main(void)
*/
vTaskDelay(pdMS_TO_TICKS(1000));
esp_sleep_wakeup_cause_t cause = esp_sleep_get_wakeup_cause();
uint32_t causes = esp_sleep_get_wakeup_causes();
/* not a wakeup from ULP, load the firmware */
if (cause != ESP_SLEEP_WAKEUP_ULP) {
if (!(causes & BIT(ESP_SLEEP_WAKEUP_ULP))) {
printf("Not a ULP-RISC-V wakeup, initializing it! \n");
wakeup_gpio_init();
init_ulp_program();
}
if (cause == ESP_SLEEP_WAKEUP_ULP) {
if (causes & BIT(ESP_SLEEP_WAKEUP_ULP)) {
printf("ULP-RISC-V woke up the main CPU! \n");
}

View File

@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2022-2024 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2022-2025 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Unlicense OR CC0-1.0
*/
@@ -52,7 +52,7 @@ void app_main(void)
int32_t pressure = 0;
oss_mode_t oss_mode;
esp_sleep_wakeup_cause_t cause = esp_sleep_get_wakeup_cause();
uint32_t causes = esp_sleep_get_wakeup_causes();
/* Not a wakeup from ULP
* Initialize RTC I2C
@@ -61,8 +61,8 @@ void app_main(void)
* Load the ULP firmware
* Go to deep sleep
*/
if (cause != ESP_SLEEP_WAKEUP_ULP) {
printf("Not a ULP-RISC V wakeup (cause = %d)\n", cause);
if (!(causes & BIT(ESP_SLEEP_WAKEUP_ULP))) {
printf("Not a ULP-RISC V wakeup (causes = %lx)\n", causes);
/* Initialize RTC I2C */
init_i2c();
@@ -76,7 +76,7 @@ void app_main(void)
ulp_riscv_i2c_master_write_to_device(&data_wr, 1);
/* Confirm that the sensor is alive
* The BMP180 returns the chip id 0x55 on quering reg addr 0xD0
* The BMP180 returns the chip id 0x55 on querying reg addr 0xD0
*/
ulp_riscv_i2c_master_set_slave_reg_addr(BMP180_SENSOR_REG_ADDR_WHO_AM_I);
ulp_riscv_i2c_master_read_from_device(&data_rd, 1);
@@ -103,7 +103,7 @@ void app_main(void)
/* Calculate real temperature value */
temperature = bmp180_calculate_real_temp((int32_t)ut_data);
printf("Real Temperature = %f deg celcius\n", (float)(temperature/10.0));
printf("Real Temperature = %f deg celsius\n", (float)(temperature/10.0));
/* Calculate real pressure value */
pressure = bmp180_calculate_real_pressure(up_data, (int32_t)ut_data, oss_mode);
@@ -120,7 +120,7 @@ void app_main(void)
}
/* ULP RISC-V read and detected a temperature or pressure above the limit */
if (cause == ESP_SLEEP_WAKEUP_ULP) {
if (causes & BIT(ESP_SLEEP_WAKEUP_ULP)) {
printf("ULP RISC-V woke up the main CPU\n");
/* Pause ULP while we are using the RTC I2C from the main CPU */
@@ -138,7 +138,7 @@ void app_main(void)
/* Calculate real temperature and pressure again */
temperature = 0;
temperature = bmp180_calculate_real_temp((int32_t)ulp_ut_data);
printf("New Real Temperature = %f deg celcius\n", (float)(temperature/10.0));
printf("New Real Temperature = %f deg celsius\n", (float)(temperature/10.0));
/* Calculate real pressure value */
pressure = 0;
@@ -283,19 +283,19 @@ static void bmp180_read_up_data(int32_t *up_data, oss_mode_t oss_mode)
{
case OSS_0:
cmd = BMP180_SENSOR_CMD_READ_PRESSURE_OSS_0;
wait = 5; // Wait atleast 4.5 msec
wait = 5; // Wait at least 4.5 msec
break;
case OSS_1:
cmd = BMP180_SENSOR_CMD_READ_PRESSURE_OSS_1;
wait = 8; // Wait atleast 7.5 msec
wait = 8; // Wait at least 7.5 msec
break;
case OSS_2:
cmd = BMP180_SENSOR_CMD_READ_PRESSURE_OSS_2;
wait = 14; // Wait atleast 13.5 msec
wait = 14; // Wait at least 13.5 msec
break;
case OSS_3:
cmd = BMP180_SENSOR_CMD_READ_PRESSURE_OSS_3;
wait = 26; // Wait atleast 25.5 msec
wait = 26; // Wait at least 25.5 msec
break;
}

View File

@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2023-2025 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Unlicense OR CC0-1.0
*/
@@ -26,15 +26,8 @@ static void init_ulp_program(void);
void app_main(void)
{
esp_sleep_wakeup_cause_t cause = esp_sleep_get_wakeup_cause();
/* not a wakeup from ULP, load the firmware */
if (cause != ESP_SLEEP_WAKEUP_ULP) {
printf("Not a ULP RISC-V wakeup, initializing it! \n");
init_ulp_program();
}
/* ULP RISC-V handled an interrupt on GPIO#0 */
if (cause == ESP_SLEEP_WAKEUP_ULP) {
if (esp_sleep_get_wakeup_causes() & BIT(ESP_SLEEP_WAKEUP_ULP)) {
/* ULP RISC-V handled an interrupt on GPIO#0 */
printf("ULP RISC-V woke up the main CPU! \n");
if (ulp_wake_by_sw) {
printf("ULP RISC-V SW Interrupt triggered %lu times.\r\n", ulp_sw_int_cnt);
@@ -43,6 +36,10 @@ void app_main(void)
printf("ULP RISC-V GPIO Interrupt triggered.\r\n");
ulp_wake_by_gpio = 0;
}
} else {
/* not a wakeup from ULP, load the firmware */
printf("Not a ULP RISC-V wakeup, initializing it! \n");
init_ulp_program();
}
/* Go back to sleep, only the ULP RISC-V will run */

View File

@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2023-2024 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2023-2025 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Unlicense OR CC0-1.0
*/
@@ -83,19 +83,8 @@ void app_main(void)
*/
vTaskDelay(pdMS_TO_TICKS(1000));
esp_sleep_wakeup_cause_t cause = esp_sleep_get_wakeup_cause();
/* not a wakeup from ULP, load the firmware */
if (cause != ESP_SLEEP_WAKEUP_ULP) {
printf("Not a ULP-RISC-V wakeup, initializing ...\n");
/* Initialize Touch peripheral */
init_touch_pad();
/* Initialize ULP core */
init_ulp_program();
}
/* ULP RISC-V detected a touch input */
if (cause == ESP_SLEEP_WAKEUP_ULP) {
if (esp_sleep_get_wakeup_causes() & BIT(ESP_SLEEP_WAKEUP_ULP)) {
/* ULP RISC-V detected a touch input */
printf("ULP-RISC-V woke up the main CPU! \n");
uint32_t touch_data = ulp_touch_data;
for (int i = 0; i < TOUCH_BUTTON_NUM; i++) {
@@ -104,6 +93,14 @@ void app_main(void)
}
}
printf("\n");
} else {
/* not a wakeup from ULP, load the firmware */
printf("Not a ULP-RISC-V wakeup, initializing ...\n");
/* Initialize Touch peripheral */
init_touch_pad();
/* Initialize ULP core */
init_ulp_program();
}
/* Go to sleep, only the ULP RISC-V will run */

View File

@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2022-2024 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2022-2025 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Unlicense OR CC0-1.0
*/
@@ -33,19 +33,15 @@ void app_main(void)
*/
vTaskDelay(pdMS_TO_TICKS(1000));
esp_sleep_wakeup_cause_t cause = esp_sleep_get_wakeup_cause();
/* not a wakeup from ULP, load the firmware */
if (cause != ESP_SLEEP_WAKEUP_ULP) {
if (esp_sleep_get_wakeup_causes() & BIT(ESP_SLEEP_WAKEUP_ULP)) {
/* ULP Risc-V read and detected a change in GPIO_0, prints */
printf("ULP-RISC-V woke up the main CPU! \n");
} else {
/* not a wakeup from ULP, load the firmware */
printf("Not a ULP-RISC-V wakeup, initializing it! \n");
init_ulp_program();
}
/* ULP Risc-V read and detected a change in GPIO_0, prints */
if (cause == ESP_SLEEP_WAKEUP_ULP) {
printf("ULP-RISC-V woke up the main CPU! \n");
}
/* Go back to sleep, only the ULP Risc-V will run */
printf("Entering in deep sleep\n\n");