From 6ed57896079c133e4bcb8b5b135eefc0f6cb8b35 Mon Sep 17 00:00:00 2001 From: wuzhenghui Date: Fri, 25 Apr 2025 11:52:15 +0800 Subject: [PATCH 1/3] fix(example): fix uninitialized gpio/rtcio in deepsleep example --- examples/system/deep_sleep/main/ext_wakeup.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/examples/system/deep_sleep/main/ext_wakeup.c b/examples/system/deep_sleep/main/ext_wakeup.c index d0e44374aee..d04736a01d7 100644 --- a/examples/system/deep_sleep/main/ext_wakeup.c +++ b/examples/system/deep_sleep/main/ext_wakeup.c @@ -7,6 +7,7 @@ #include #include "esp_sleep.h" #include "sdkconfig.h" +#include "driver/gpio.h" #include "driver/rtc_io.h" #include "driver/gpio.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)); } @@ -52,6 +54,8 @@ void example_deep_sleep_register_ext1_wakeup(void) * 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 571f3b2a91044c9729a6cfd73519070048d64302 Mon Sep 17 00:00:00 2001 From: wuzhenghui Date: Thu, 24 Apr 2025 16:42:02 +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 | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/components/esp_hw_support/sleep_modes.c b/components/esp_hw_support/sleep_modes.c index 81d91ca8dca..9702fdc1730 100644 --- a/components/esp_hw_support/sleep_modes.c +++ b/components/esp_hw_support/sleep_modes.c @@ -372,7 +372,7 @@ static void touch_wakeup_prepare(void); #if SOC_VBAT_SUPPORTED static void vbat_under_volt_wakeup_prepare(void); #endif -#if SOC_GPIO_SUPPORT_HP_PERIPH_PD_SLEEP_WAKEUP && SOC_DEEP_SLEEP_SUPPORTED +#if SOC_GPIO_SUPPORT_HP_PERIPH_PD_SLEEP_WAKEUP static void esp_sleep_gpio_wakeup_prepare_on_hp_periph_powerdown(void); #endif @@ -1039,8 +1039,8 @@ static esp_err_t SLEEP_FN_ATTR esp_sleep_start(uint32_t sleep_flags, uint32_t cl // for !(s_config.wakeup_triggers & RTC_EXT1_TRIG_EN), ext1 wakeup will be turned off in hardware in the real call to sleep #endif -#if SOC_GPIO_SUPPORT_HP_PERIPH_PD_SLEEP_WAKEUP && SOC_DEEP_SLEEP_SUPPORTED - if (deep_sleep && (s_config.wakeup_triggers & RTC_GPIO_TRIG_EN)) { +#if SOC_GPIO_SUPPORT_HP_PERIPH_PD_SLEEP_WAKEUP + if ((sleep_flags & RTC_SLEEP_PD_DIG) && (s_config.wakeup_triggers & RTC_GPIO_TRIG_EN)) { esp_sleep_gpio_wakeup_prepare_on_hp_periph_powerdown(); } #endif @@ -2173,7 +2173,7 @@ uint64_t esp_sleep_get_ext1_wakeup_status(void) #endif // SOC_PM_SUPPORT_EXT1_WAKEUP && SOC_RTCIO_PIN_COUNT > 0 -#if SOC_GPIO_SUPPORT_HP_PERIPH_PD_SLEEP_WAKEUP && SOC_DEEP_SLEEP_SUPPORTED +#if SOC_GPIO_SUPPORT_HP_PERIPH_PD_SLEEP_WAKEUP uint64_t esp_sleep_get_gpio_wakeup_status(void) { if (!(esp_sleep_get_wakeup_causes() & BIT(ESP_SLEEP_WAKEUP_GPIO))) { From 8ff8f8d0b9b18aabc3240c909fd00911e959fd5e Mon Sep 17 00:00:00 2001 From: wuzhenghui Date: Tue, 20 Jan 2026 12:02:24 +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 9702fdc1730..0dfc8ec5c9b 100644 --- a/components/esp_hw_support/sleep_modes.c +++ b/components/esp_hw_support/sleep_modes.c @@ -1726,6 +1726,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; #if SOC_PMU_SUPPORTED && (SOC_UART_HP_NUM > 2) } else if (CHECK_SOURCE(source, ESP_SLEEP_WAKEUP_UART, (RTC_UART0_TRIG_EN | RTC_UART1_TRIG_EN | RTC_UART2_TRIG_EN))) { @@ -2233,12 +2237,12 @@ esp_err_t esp_sleep_enable_gpio_wakeup_on_hp_periph_powerdown(uint64_t gpio_pin_ continue; } err = gpio_wakeup_enable_on_hp_periph_powerdown_sleep(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;