From 44cd96b5432b8e5963767097e831893a25c1b085 Mon Sep 17 00:00:00 2001 From: Lou Tianhao Date: Tue, 11 Jul 2023 17:15:59 +0800 Subject: [PATCH] change(pm/deepsleep): remove disable rtcio before hold it when ext1 wakeup --- components/esp_hw_support/sleep_modes.c | 19 ++++------ .../system/deep_sleep/main/Kconfig.projbuild | 7 ++-- examples/system/deep_sleep/main/ext_wakeup.c | 36 +++++++++++++------ 3 files changed, 35 insertions(+), 27 deletions(-) diff --git a/components/esp_hw_support/sleep_modes.c b/components/esp_hw_support/sleep_modes.c index 035cedb024..67c736d90c 100644 --- a/components/esp_hw_support/sleep_modes.c +++ b/components/esp_hw_support/sleep_modes.c @@ -1416,6 +1416,12 @@ static void ext1_wakeup_prepare(void) rtcio_hal_function_select(rtc_pin, RTCIO_FUNC_RTC); // set input enable in sleep mode rtcio_hal_input_enable(rtc_pin); +#if SOC_PM_SUPPORT_RTC_PERIPH_PD + // Pad configuration depends on RTC_PERIPH state in sleep mode + if (s_config.domain[ESP_PD_DOMAIN_RTC_PERIPH].pd_option != ESP_PD_OPTION_ON) { + rtcio_hal_hold_enable(rtc_pin); + } +#endif #else /* ESP32H2 use hp iomux to config rtcio, and there is no complete * rtcio functionality. In the case of EXT1 wakeup, rtcio only provides @@ -1427,19 +1433,6 @@ static void ext1_wakeup_prepare(void) gpio_ll_input_enable(&GPIO, gpio); // hold rtc_pin to use it during sleep state rtcio_hal_hold_enable(rtc_pin); -#endif -#if SOC_PM_SUPPORT_RTC_PERIPH_PD - // Pad configuration depends on RTC_PERIPH state in sleep mode - if (s_config.domain[ESP_PD_DOMAIN_RTC_PERIPH].pd_option != ESP_PD_OPTION_ON) { -#if SOC_RTCIO_INPUT_OUTPUT_SUPPORTED - // RTC_PERIPH will be powered down, so RTC_IO_ registers will - // loose their state. Lock pad configuration. - // Pullups/pulldowns also need to be disabled. - rtcio_hal_pullup_disable(rtc_pin); - rtcio_hal_pulldown_disable(rtc_pin); -#endif - rtcio_hal_hold_enable(rtc_pin); - } #endif // Keep track of pins which are processed to bail out early rtc_gpio_mask &= ~BIT(rtc_pin); diff --git a/examples/system/deep_sleep/main/Kconfig.projbuild b/examples/system/deep_sleep/main/Kconfig.projbuild index 96bd151b9f..0c16340f73 100644 --- a/examples/system/deep_sleep/main/Kconfig.projbuild +++ b/examples/system/deep_sleep/main/Kconfig.projbuild @@ -244,9 +244,10 @@ menu "Example Configuration" When using EXT1 wakeup source without external pull-up/downs, you may want to make use of the internal ones. - However, the RTC IO reside in the RTC Periph power domain. Enable this option to force that - power domain ON during deep sleep. Note that this will increase some power comsumption, so - it's still suggested to use external ones instead. + 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. + but if we turn on the RTC_PERIPH domain, we don not need to use HOLD feature and this will + increase some power comsumption. EXT0 wakeup source resides in the same power domain as RTCIO (RTC Periph), so internal pull-up/downs are always available. There's no need to explicitly force it on for EXT0. diff --git a/examples/system/deep_sleep/main/ext_wakeup.c b/examples/system/deep_sleep/main/ext_wakeup.c index 03870075ff..3f2590be35 100644 --- a/examples/system/deep_sleep/main/ext_wakeup.c +++ b/examples/system/deep_sleep/main/ext_wakeup.c @@ -49,19 +49,33 @@ 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. */ + * increase some power comsumption. 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 !CONFIG_IDF_TARGET_ESP32H2 - ESP_ERROR_CHECK(esp_sleep_pd_config(ESP_PD_DOMAIN_RTC_PERIPH, ESP_PD_OPTION_ON)); - ESP_ERROR_CHECK(rtc_gpio_pullup_dis(ext_wakeup_pin_1)); - ESP_ERROR_CHECK(rtc_gpio_pulldown_en(ext_wakeup_pin_1)); - ESP_ERROR_CHECK(rtc_gpio_pullup_dis(ext_wakeup_pin_2)); - ESP_ERROR_CHECK(rtc_gpio_pulldown_en(ext_wakeup_pin_2)); +#if SOC_RTCIO_INPUT_OUTPUT_SUPPORTED + if (ext_wakeup_mode) { + ESP_ERROR_CHECK(rtc_gpio_pullup_dis(ext_wakeup_pin_1)); + ESP_ERROR_CHECK(rtc_gpio_pulldown_en(ext_wakeup_pin_1)); + ESP_ERROR_CHECK(rtc_gpio_pullup_dis(ext_wakeup_pin_2)); + ESP_ERROR_CHECK(rtc_gpio_pulldown_en(ext_wakeup_pin_2)); + } else { + ESP_ERROR_CHECK(rtc_gpio_pulldown_dis(ext_wakeup_pin_1)); + ESP_ERROR_CHECK(rtc_gpio_pullup_en(ext_wakeup_pin_1)); + ESP_ERROR_CHECK(rtc_gpio_pulldown_dis(ext_wakeup_pin_2)); + ESP_ERROR_CHECK(rtc_gpio_pullup_en(ext_wakeup_pin_2)); + } #else - gpio_pullup_dis(ext_wakeup_pin_1); - gpio_pulldown_en(ext_wakeup_pin_1); - gpio_pullup_dis(ext_wakeup_pin_2); - gpio_pulldown_en(ext_wakeup_pin_2); + if (ext_wakeup_mode) { + ESP_ERROR_CHECK(gpio_pullup_dis(ext_wakeup_pin_1)); + ESP_ERROR_CHECK(gpio_pulldown_en(ext_wakeup_pin_1)); + ESP_ERROR_CHECK(gpio_pullup_dis(ext_wakeup_pin_2)); + ESP_ERROR_CHECK(gpio_pulldown_en(ext_wakeup_pin_2)); + } else { + ESP_ERROR_CHECK(gpio_pulldown_dis(ext_wakeup_pin_1)); + ESP_ERROR_CHECK(gpio_pullup_en(ext_wakeup_pin_1)); + ESP_ERROR_CHECK(gpio_pulldown_dis(ext_wakeup_pin_2)); + ESP_ERROR_CHECK(gpio_pullup_en(ext_wakeup_pin_2)); + } #endif #endif //CONFIG_EXAMPLE_EXT1_USE_INTERNAL_PULLUPS }