From acdf49a5acec6f61c220b8461aa535f98deac511 Mon Sep 17 00:00:00 2001 From: Li Shuai Date: Thu, 16 Sep 2021 16:30:28 +0800 Subject: [PATCH] light sleep: fix SPIRAM leakage when its CS pin has no hardware pullup --- components/esp_system/Kconfig | 9 +++++++++ components/esp_system/sleep_modes.c | 6 ++++++ 2 files changed, 15 insertions(+) diff --git a/components/esp_system/Kconfig b/components/esp_system/Kconfig index e82335d2d3..cf26ebf951 100644 --- a/components/esp_system/Kconfig +++ b/components/esp_system/Kconfig @@ -100,6 +100,15 @@ menu "ESP System Settings" If enabled, the CPU will be powered down in light sleep. Enabling this option will consume 1.68 KB of internal RAM and will reduce sleep current consumption by about 100 uA. + config ESP_SYSTEM_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. + menu "Memory protection" config ESP_SYSTEM_MEMPROT_FEATURE diff --git a/components/esp_system/sleep_modes.c b/components/esp_system/sleep_modes.c index 8aaa1b18a5..e0fc4df91a 100644 --- a/components/esp_system/sleep_modes.c +++ b/components/esp_system/sleep_modes.c @@ -53,6 +53,7 @@ #include "esp32/clk.h" #include "esp32/rom/rtc.h" #include "esp_private/gpio.h" +#include "esp32/spiram.h" #elif CONFIG_IDF_TARGET_ESP32S2 #include "esp32s2/clk.h" #include "esp32s2/rom/cache.h" @@ -60,11 +61,13 @@ #include "esp32s2/brownout.h" #include "soc/extmem_reg.h" #include "esp_private/gpio.h" +#include "esp32s2/spiram.h" #elif CONFIG_IDF_TARGET_ESP32S3 #include "esp32s3/clk.h" #include "esp32s3/rom/cache.h" #include "esp32s3/rom/rtc.h" #include "soc/extmem_reg.h" +#include "esp32s3/spiram.h" #elif CONFIG_IDF_TARGET_ESP32C3 #include "esp32c3/clk.h" #include "esp32c3/rom/cache.h" @@ -418,6 +421,9 @@ void esp_sleep_config_gpio_isolate(void) gpio_sleep_set_pull_mode(gpio_num, GPIO_FLOATING); } } +#if CONFIG_ESP_SYSTEM_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)