From af4f2075acb000d327085dba08f4666e22fca432 Mon Sep 17 00:00:00 2001 From: Li Shuai Date: Sat, 3 Jul 2021 10:57:49 +0800 Subject: [PATCH] light sleep: fix SPIRAM leakage when its CS pin has no hardware pullup --- components/esp_hw_support/Kconfig | 9 +++++++++ components/esp_hw_support/sleep_gpio.c | 11 +++++++++++ 2 files changed, 20 insertions(+) diff --git a/components/esp_hw_support/Kconfig b/components/esp_hw_support/Kconfig index bf8443b296..58f90e64da 100644 --- a/components/esp_hw_support/Kconfig +++ b/components/esp_hw_support/Kconfig @@ -33,5 +33,14 @@ menu "Hardware Settings" config ESP_SLEEP_RTC_BUS_ISO_WORKAROUND bool default y if IDF_TARGET_ESP32 || IDF_TARGET_ESP32S2 || IDF_TARGET_ESP32S3 + + config ESP_SLEEP_PSRAM_LEAKAGE_WORKAROUND + bool "PSRAM leakage current workaround in light sleep" + depends on SPIRAM + help + When the CS pin of SPIRAM is not pulled up, the sleep current will + increase during light sleep. If the CS pin of SPIRAM has an external + pull-up, you do not need to select this option, otherwise, you + should enable this option. endmenu endmenu diff --git a/components/esp_hw_support/sleep_gpio.c b/components/esp_hw_support/sleep_gpio.c index 776ef053d8..f7b8a1726c 100644 --- a/components/esp_hw_support/sleep_gpio.c +++ b/components/esp_hw_support/sleep_gpio.c @@ -20,6 +20,14 @@ #include "esp_private/gpio.h" #include "esp_private/sleep_gpio.h" +#ifdef CONFIG_IDF_TARGET_ESP32 +#include "esp32/spiram.h" +#elif CONFIG_IDF_TARGET_ESP32S2 +#include "esp32s2/spiram.h" +#elif CONFIG_IDF_TARGET_ESP32S3 +#include "esp32s3/spiram.h" +#endif + static const char *TAG = "sleep"; #if SOC_GPIO_SUPPORT_SLP_SWITCH @@ -53,6 +61,9 @@ void esp_sleep_config_gpio_isolate(void) gpio_sleep_set_pull_mode(gpio_num, GPIO_FLOATING); } } +#if CONFIG_ESP_SLEEP_PSRAM_LEAKAGE_WORKAROUND && CONFIG_SPIRAM + gpio_sleep_set_pull_mode(esp_spiram_get_cs_io(), GPIO_PULLUP_ONLY); +#endif } void esp_sleep_enable_gpio_switch(bool enable)