From 86e5252d63bc2db4d797d6a766b7a22af4dc684b Mon Sep 17 00:00:00 2001 From: Lou Tianhao Date: Tue, 19 Sep 2023 10:59:57 +0800 Subject: [PATCH] feat(pm): add internal pull-up/downs option for gpio used for deepsleep wakeup --- components/esp_hw_support/Kconfig | 7 +++++++ components/esp_hw_support/include/esp_sleep.h | 12 ++++++++---- components/esp_hw_support/sleep_modes.c | 2 ++ 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/components/esp_hw_support/Kconfig b/components/esp_hw_support/Kconfig index 11d938e4d2..a968c45543 100644 --- a/components/esp_hw_support/Kconfig +++ b/components/esp_hw_support/Kconfig @@ -154,6 +154,13 @@ menu "Hardware Settings" If you are seeing "flash read err, 1000" message printed to the console after deep sleep reset, try increasing this value. + + config ESP_SLEEP_GPIO_ENABLE_INTERNAL_RESISTORS + bool "Allow to enable internal pull-up/downs for the Deep-Sleep wakeup IOs" + default y + help + When using rtc gpio wakeup source during deepsleep without external pull-up/downs, you may want to + make use of the internal ones. endmenu menu "ESP_SLEEP_WORKAROUND" diff --git a/components/esp_hw_support/include/esp_sleep.h b/components/esp_hw_support/include/esp_sleep.h index a836a399c2..548ca98d06 100644 --- a/components/esp_hw_support/include/esp_sleep.h +++ b/components/esp_hw_support/include/esp_sleep.h @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2015-2021 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2015-2023 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -280,9 +280,13 @@ esp_err_t esp_sleep_enable_ext1_wakeup(uint64_t mask, esp_sleep_ext1_wakeup_mode * @note This function does not modify pin configuration. The pins are * configured inside esp_deep_sleep_start, immediately before entering sleep mode. * - * @note You don't need to care to pull-up or pull-down before using this - * function, because this will be set internally in esp_deep_sleep_start - * based on the wakeup mode. BTW, when you use low level to wake up the + * @note You don't need to worry about pull-up or pull-down resistors before + * using this function because the ESP_SLEEP_GPIO_ENABLE_INTERNAL_RESISTORS + * option is enabled by default. It will automatically set pull-up or pull-down + * resistors internally in esp_deep_sleep_start based on the wakeup mode. However, + * when using external pull-up or pull-down resistors, please be sure to disable + * the ESP_SLEEP_GPIO_ENABLE_INTERNAL_RESISTORS option, as the combination of internal + * and external resistors may cause interference. BTW, when you use low level to wake up the * chip, we strongly recommend you to add external resistors (pull-up). * * @param gpio_pin_mask Bit mask of GPIO numbers which will cause wakeup. Only GPIOs diff --git a/components/esp_hw_support/sleep_modes.c b/components/esp_hw_support/sleep_modes.c index 1b34628fd0..984e6767f1 100644 --- a/components/esp_hw_support/sleep_modes.c +++ b/components/esp_hw_support/sleep_modes.c @@ -1445,6 +1445,7 @@ static void gpio_deep_sleep_wakeup_prepare(void) if (((1ULL << gpio_idx) & s_config.gpio_wakeup_mask) == 0) { continue; } +#if CONFIG_ESP_SLEEP_GPIO_ENABLE_INTERNAL_RESISTORS if (s_config.gpio_trigger_mode & BIT(gpio_idx)) { ESP_ERROR_CHECK(gpio_pullup_dis(gpio_idx)); ESP_ERROR_CHECK(gpio_pulldown_en(gpio_idx)); @@ -1452,6 +1453,7 @@ static void gpio_deep_sleep_wakeup_prepare(void) ESP_ERROR_CHECK(gpio_pullup_en(gpio_idx)); ESP_ERROR_CHECK(gpio_pulldown_dis(gpio_idx)); } +#endif ESP_ERROR_CHECK(gpio_hold_en(gpio_idx)); } // Clear state from previous wakeup