Cut ESP32 deep sleep leakage with rtc_gpio_isolate
Stop an ESP32 pin leaking current during deep sleep by calling rtc_gpio_isolate on an RTC-capable pin in ESP-IDF v5.4 before sleeping.
A board's external pull-up on an ESP32 pin can feed current into the chip through its internal circuit while the chip sleeps, and in deep sleep every microamp counts. ESP-IDF v5.4 provides rtc_gpio_isolate, which disconnects the pad from the digital side and holds it, so the leak path is cut. The Espressif sleep documentation names GPIO12 on a module with an external pull-up as the usual case.
#include <stdio.h>
#include "driver/rtc_io.h"
#include "esp_sleep.h"
void app_main(void)
{
esp_err_t err = rtc_gpio_isolate(GPIO_NUM_12);
printf("isolate: %s\n", esp_err_to_name(err));
esp_sleep_enable_timer_wakeup(10 * 1000000ULL);
esp_deep_sleep_start();
}isolate: ESP_OKThe call only accepts pins that belong to the RTC IO block. GPIO12 is RTC_GPIO15 on the ESP32, so it works, and an ordinary digital-only pin returns ESP_ERR_INVALID_ARG. Isolation holds through deep sleep, and after wake-up you must release it with rtc_gpio_hold_dis before driving the pin again. See the ESP-IDF sleep modes guide, which has a section on GPIO state in sleep.
Do not isolate a pin you use as a wake-up source or as an output that must keep its level: use rtc_gpio_hold_en for the latter.