From af6cfc5552a03baf7db521d0e0178037bbae5c64 Mon Sep 17 00:00:00 2001 From: Ivan Grokhotkov Date: Sat, 10 Feb 2018 00:34:38 +0800 Subject: [PATCH] docs, examples: use rtc_gpio_isolate to disconnect GPIO12 This is needed to reduce deep sleep current on ESP32-WROVER modules. Ref TW18165. --- docs/api-reference/system/sleep_modes.rst | 14 ++++++++++++++ examples/system/console/main/cmd_system.c | 1 + .../deep_sleep/main/deep_sleep_example_main.c | 5 +++++ examples/system/ulp/main/ulp_example_main.c | 10 ++++++---- .../system/ulp_adc/main/ulp_adc_example_main.c | 10 ++++++---- 5 files changed, 32 insertions(+), 8 deletions(-) diff --git a/docs/api-reference/system/sleep_modes.rst b/docs/api-reference/system/sleep_modes.rst index 8a46c91d1..3e6d8344b 100644 --- a/docs/api-reference/system/sleep_modes.rst +++ b/docs/api-reference/system/sleep_modes.rst @@ -122,6 +122,20 @@ The following function can be used to enter deep sleep once wakeup sources are c .. doxygenfunction:: esp_deep_sleep_start +Configuring IOs +--------------- + +Some ESP32 IOs have internal pullups or pulldowns, which are enabled by default. If an external circuit drives this pin in deep sleep mode, current consumption may increase due to current flowing through these pullups and pulldowns. + +To isolate a pin, preventing extra current draw, call :cpp:func:`rtc_gpio_isolate` function. + +For example, on ESP32-WROVER module, GPIO12 is pulled up externally. GPIO12 also has an internal pulldown in the ESP32 chip. This means that in deep sleep, some current will flow through these external and internal resistors, increasing deep sleep current above the minimal possible value. +Add the following code before :cpp:func:`esp_deep_sleep_start` to remove this extra current: + +```c++ +rtc_gpio_isolate(GPIO_NUM_12); +``` + Checking sleep wakeup cause --------------------------- diff --git a/examples/system/console/main/cmd_system.c b/examples/system/console/main/cmd_system.c index 04003e8d5..343b65be6 100644 --- a/examples/system/console/main/cmd_system.c +++ b/examples/system/console/main/cmd_system.c @@ -113,6 +113,7 @@ static int deep_sleep(int argc, char** argv) ESP_ERROR_CHECK( esp_sleep_enable_ext1_wakeup(1ULL << io_num, level) ); } + rtc_gpio_isolate(GPIO_NUM_12); esp_deep_sleep_start(); } diff --git a/examples/system/deep_sleep/main/deep_sleep_example_main.c b/examples/system/deep_sleep/main/deep_sleep_example_main.c index 5a4f33f7b..32e4fc3fa 100644 --- a/examples/system/deep_sleep/main/deep_sleep_example_main.c +++ b/examples/system/deep_sleep/main/deep_sleep_example_main.c @@ -157,6 +157,11 @@ void app_main() esp_sleep_enable_ulp_wakeup(); #endif + // Isolate GPIO12 pin from external circuits. This is needed for modules + // which have an external pull-up resistor on GPIO12 (such as ESP32-WROVER) + // to minimize current consumption. + rtc_gpio_isolate(GPIO_NUM_12); + printf("Entering deep sleep\n"); gettimeofday(&sleep_enter_time, NULL); diff --git a/examples/system/ulp/main/ulp_example_main.c b/examples/system/ulp/main/ulp_example_main.c index 650744e88..873a17620 100644 --- a/examples/system/ulp/main/ulp_example_main.c +++ b/examples/system/ulp/main/ulp_example_main.c @@ -68,11 +68,13 @@ static void init_ulp_program() rtc_gpio_pullup_dis(gpio_num); rtc_gpio_hold_en(gpio_num); - /* Disable pullup on GPIO15, in case it is connected to ground to suppress - * boot messages. + /* Disconnect GPIO12 and GPIO15 to remove current drain through + * pullup/pulldown resistors. + * GPIO15 may be connected to ground to suppress boot messages. + * GPIO12 may be pulled high to select flash voltage. */ - rtc_gpio_pullup_dis(GPIO_NUM_15); - rtc_gpio_hold_en(GPIO_NUM_15); + rtc_gpio_isolate(GPIO_NUM_12); + rtc_gpio_isolate(GPIO_NUM_15); /* Set ULP wake up period to T = 20ms (3095 cycles of RTC_SLOW_CLK clock). * Minimum pulse width has to be T * (ulp_debounce_counter + 1) = 80ms. diff --git a/examples/system/ulp_adc/main/ulp_adc_example_main.c b/examples/system/ulp_adc/main/ulp_adc_example_main.c index 5e43ca22d..29d8eac9a 100644 --- a/examples/system/ulp_adc/main/ulp_adc_example_main.c +++ b/examples/system/ulp_adc/main/ulp_adc_example_main.c @@ -74,11 +74,13 @@ static void init_ulp_program() /* Set ULP wake up period to 20ms */ ulp_set_wakeup_period(0, 20000); - /* Disable pullup on GPIO15, in case it is connected to ground to suppress - * boot messages. + /* Disconnect GPIO12 and GPIO15 to remove current drain through + * pullup/pulldown resistors. + * GPIO15 may be connected to ground to suppress boot messages. + * GPIO12 may be pulled high to select flash voltage. */ - rtc_gpio_pullup_dis(GPIO_NUM_15); - rtc_gpio_hold_en(GPIO_NUM_15); + rtc_gpio_isolate(GPIO_NUM_12); + rtc_gpio_isolate(GPIO_NUM_15); } static void start_ulp_program()