From a0ca0c9de913fa51c4ab75bf68940e45a8589a25 Mon Sep 17 00:00:00 2001 From: wuzhenghui Date: Fri, 13 Feb 2026 12:11:29 +0800 Subject: [PATCH 1/3] fix(example): fix uninitialized gpio/rtcio in deepsleep example --- examples/system/deep_sleep/main/ext_wakeup.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/examples/system/deep_sleep/main/ext_wakeup.c b/examples/system/deep_sleep/main/ext_wakeup.c index 9768faab21..305542a5bd 100644 --- a/examples/system/deep_sleep/main/ext_wakeup.c +++ b/examples/system/deep_sleep/main/ext_wakeup.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2023-2024 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2023-2026 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Unlicense OR CC0-1.0 */ @@ -7,6 +7,7 @@ #include #include "esp_sleep.h" #include "sdkconfig.h" +#include "driver/gpio.h" #include "driver/rtc_io.h" @@ -25,6 +26,7 @@ void example_deep_sleep_register_ext0_wakeup(void) // Configure pullup/downs via RTCIO to tie wakeup pins to inactive level during deepsleep. // EXT0 resides in the same power domain (RTC_PERIPH) as the RTC IO pullup/downs. // No need to keep that power domain explicitly, unlike EXT1. + ESP_ERROR_CHECK(rtc_gpio_init(ext_wakeup_pin_0)); ESP_ERROR_CHECK(rtc_gpio_pullup_dis(ext_wakeup_pin_0)); ESP_ERROR_CHECK(rtc_gpio_pulldown_en(ext_wakeup_pin_0)); } @@ -48,10 +50,12 @@ void example_deep_sleep_register_ext1_wakeup(void) /* If there are no external pull-up/downs, tie wakeup pins to inactive level with internal pull-up/downs via RTC IO * during deepsleep. However, RTC IO relies on the RTC_PERIPH power domain. Keeping this power domain on will - * increase some power comsumption. However, if we turn off the RTC_PERIPH domain or if certain chips lack the RTC_PERIPH + * increase some power consumption. However, if we turn off the RTC_PERIPH domain or if certain chips lack the RTC_PERIPH * domain, we will use the HOLD feature to maintain the pull-up and pull-down on the pins during sleep.*/ #if CONFIG_EXAMPLE_EXT1_USE_INTERNAL_PULLUPS #if SOC_RTCIO_INPUT_OUTPUT_SUPPORTED + ESP_ERROR_CHECK(rtc_gpio_init(ext_wakeup_pin_1)); + ESP_ERROR_CHECK(rtc_gpio_init(ext_wakeup_pin_2)); #if SOC_PM_SUPPORT_EXT1_WAKEUP_MODE_PER_PIN if (CONFIG_EXAMPLE_EXT1_WAKEUP_MODE_PIN_1) { ESP_ERROR_CHECK(rtc_gpio_pullup_dis(ext_wakeup_pin_1)); @@ -81,6 +85,11 @@ void example_deep_sleep_register_ext1_wakeup(void) } #endif #else // ! SOC_RTCIO_INPUT_OUTPUT_SUPPORTED + const gpio_config_t config = { + .pin_bit_mask = BIT(ext_wakeup_pin_1) | BIT(ext_wakeup_pin_2), + .mode = GPIO_MODE_INPUT, + }; + ESP_ERROR_CHECK(gpio_config(&config)); #if SOC_PM_SUPPORT_EXT1_WAKEUP_MODE_PER_PIN if (CONFIG_EXAMPLE_EXT1_WAKEUP_MODE_PIN_1) { gpio_pullup_dis(ext_wakeup_pin_1); From 394363732584941718a459915c9b32d775624eed Mon Sep 17 00:00:00 2001 From: wuzhenghui Date: Fri, 13 Feb 2026 12:11:55 +0800 Subject: [PATCH 2/3] fix(esp_hw_support): make esp_deep_sleep_enable_gpio_wakeup available to PD_TOP lightsleep --- components/esp_hw_support/sleep_modes.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/esp_hw_support/sleep_modes.c b/components/esp_hw_support/sleep_modes.c index 786768f9bc..5e7daa9613 100644 --- a/components/esp_hw_support/sleep_modes.c +++ b/components/esp_hw_support/sleep_modes.c @@ -801,7 +801,7 @@ static esp_err_t IRAM_ATTR esp_sleep_start(uint32_t pd_flags, esp_sleep_mode_t m #endif #if SOC_GPIO_SUPPORT_DEEPSLEEP_WAKEUP - if (deep_sleep && (s_config.wakeup_triggers & RTC_GPIO_TRIG_EN)) { + if ((pd_flags & RTC_SLEEP_PD_DIG) && (s_config.wakeup_triggers & RTC_GPIO_TRIG_EN)) { gpio_deep_sleep_wakeup_prepare(); } #endif From f85a5dee4d54a3adbc664465ed5027ca31e3751a Mon Sep 17 00:00:00 2001 From: wuzhenghui Date: Fri, 13 Feb 2026 12:12:17 +0800 Subject: [PATCH 3/3] fix(esp_hw_support): fix esp_sleep_enable_gpio_wakeup_on_hp_periph_powerdown bad logic --- components/esp_hw_support/sleep_modes.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/components/esp_hw_support/sleep_modes.c b/components/esp_hw_support/sleep_modes.c index 5e7daa9613..24f8a5d8ef 100644 --- a/components/esp_hw_support/sleep_modes.c +++ b/components/esp_hw_support/sleep_modes.c @@ -1465,6 +1465,10 @@ esp_err_t esp_sleep_disable_wakeup_source(esp_sleep_source_t source) s_config.wakeup_triggers &= ~RTC_TOUCH_TRIG_EN; #endif } else if (CHECK_SOURCE(source, ESP_SLEEP_WAKEUP_GPIO, RTC_GPIO_TRIG_EN)) { +#if SOC_GPIO_SUPPORT_DEEPSLEEP_WAKEUP + s_config.gpio_wakeup_mask = 0; + s_config.gpio_trigger_mode = 0; +#endif s_config.wakeup_triggers &= ~RTC_GPIO_TRIG_EN; } else if (CHECK_SOURCE(source, ESP_SLEEP_WAKEUP_UART, (RTC_UART0_TRIG_EN | RTC_UART1_TRIG_EN))) { s_config.wakeup_triggers &= ~(RTC_UART0_TRIG_EN | RTC_UART1_TRIG_EN); @@ -1878,12 +1882,12 @@ esp_err_t esp_deep_sleep_enable_gpio_wakeup(uint64_t gpio_pin_mask, esp_deepslee return ESP_ERR_INVALID_ARG; } err = gpio_deep_sleep_wakeup_enable(gpio_idx, intr_type); - + if (err != ESP_OK) return err; s_config.gpio_wakeup_mask |= BIT(gpio_idx); if (mode == ESP_GPIO_WAKEUP_GPIO_HIGH) { - s_config.gpio_trigger_mode |= (mode << gpio_idx); + s_config.gpio_trigger_mode |= BIT(gpio_idx); } else { - s_config.gpio_trigger_mode &= ~(mode << gpio_idx); + s_config.gpio_trigger_mode &= ~BIT(gpio_idx); } } s_config.wakeup_triggers |= RTC_GPIO_TRIG_EN;