Skip to content

not defining esp_deep_sleep_enable_gpio_wakeup() on esp32-h2 mcu #11434

@VigilusPrime

Description

@VigilusPrime

Board

esp32-h2

Device Description

Hello. While working on deep-sleep wakeup finds problem with gpio wakeup on esp32-h2. In API guide wrote using esp_deep_sleep_enable_gpio_wakeup to wakeup, but in ide this function not available for esp32-h2 board

Hardware Configuration

GPIO 12 connecting via button to GND

Version

latest stable Release (if not listed below)

IDE Name

VScode

Operating System

windows 11

Flash frequency

40MHz

PSRAM enabled

yes

Upload speed

115200

Description

Hello. While working on deep-sleep wakeup finds problem with gpio wakeup on esp32-h2. In API guide wrote using esp_deep_sleep_enable_gpio_wakeup to wakeup, but in ide this function not available for esp32-h2 board

Sketch

static void deep_sleep_task(void *pvParameters){
    gpio_wakeup_enable(GPIO_PIN_BUTON,GPIO_INTR_LOW_LEVEL);
    esp_deep_sleep_enable_gpio_wakeup(GPIO_PIN_BUTON);
    bool button_st;
    while(1){
        if (xQueueReceive(button_queue, &button_st, portMAX_DELAY)) {
            gpio_intr_disable(GPIO_PIN_BUTON);
            int64_t timer = 0;
            vTaskDelay(pdMS_TO_TICKS(50));
            if (gpio_get_level(GPIO_PIN_BUTON) == 0){

                ESP_LOGI("ISR", "Button is pressed");
                timer = esp_timer_get_time();
            }
            while(gpio_get_level(GPIO_PIN_BUTON) == 0);
            vTaskDelay(pdMS_TO_TICKS(50));
            if (gpio_get_level(GPIO_PIN_BUTON) == 1){
                ESP_LOGI("ISR", "Button is released");
                if((esp_timer_get_time() - timer)>= 3000000){

                    ESP_LOGI("ESP", "Entering in Deep Sleep");
                    esp_deep_sleep_start();
                }else{timer = 0;}
            }
            
            gpio_intr_enable(GPIO_PIN_BUTON);
        }
    }
}

Debug Message

C:/Users/fedot/Documents/X-TechProjects/X-RT/main/esp_zb_light.c:1740:5: error: implicit declaration of function 'esp_deep_sleep_enable_gpio_wakeup'; did you mean 'esp_sleep_enable_gpio_wakeup'? [-Wimplicit-function-declaration]
 1740 |     esp_deep_sleep_enable_gpio_wakeup(GPIO_PIN_BUTON);
      |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      |     esp_sleep_enable_gpio_wakeup

Other Steps to Reproduce

No response

I have checked existing issues, online documentation and the Troubleshooting Guide

  • I confirm I have checked existing issues, online documentation and Troubleshooting guide.

Activity

SuGlider

SuGlider commented on Jun 4, 2025

@SuGlider
Collaborator

Please reefer to IDF deep sleep example:
https://github.com/espressif/esp-idf/tree/master/examples/system/deep_sleep
H2 can use EXT1 or GPIO (only for pads powered by VDD3P3_RTC) as wakeup source.

Don't forget to include necessary header files

#include "driver/gpio.h"
#include "esp_sleep.h"
SuGlider

SuGlider commented on Jun 4, 2025

@SuGlider
Collaborator

@VigilusPrime - esp_deep_sleep_enable_gpio_wakeup() is not supported by ESP32-H2.

Based on https://github.com/espressif/esp-idf/blob/release/v5.4/components/esp_driver_gpio/include/driver/gpio.h#L548-L579
In order to support esp_err_t gpio_deep_sleep_wakeup_enable(gpio_num_t gpio_num, gpio_int_type_t intr_type);, the SoC must define SOC_GPIO_SUPPORT_DEEPSLEEP_WAKEUP which is not the case for ESP32-H2.

SOC_GPIO_SUPPORT_DEEPSLEEP_WAKEUP is valid for ESP32-C2, ESP32-C3, ESP32-C5, ESP32-C6, ESP32-C61 and ESP32-P4 only.

Therefore, the sketch should use EXT1 as Deepsleep wakeup source.
https://docs.espressif.com/projects/esp-idf/en/v5.4.1/esp32h2/api-reference/system/sleep_modes.html

NOTE: Only GPIO7~14 on ESP32H2 can support chip deep sleep wakeup through EXT1 wake up

ESP32-H2 GPIO9 is used as BOOT Button.

This example works:

#include "driver/rtc_io.h"

#define BUTTON_PIN_BITMASK(GPIO) (1ULL << GPIO)  // 2 ^ GPIO_NUMBER in hex

// ESP32-H2 can use only EXT1 as Wakeup source
// Only RTC IO are allowed - GPIO7 ~ GPIO14
#define WAKEUP_GPIO              GPIO_NUM_9     // ESP32-H2 DevKit Boot Button
RTC_DATA_ATTR int bootCount = 0;

// Method to print the reason by which the SoC has been awaken from sleep
void print_wakeup_reason() {
  esp_sleep_wakeup_cause_t wakeup_reason;
  wakeup_reason = esp_sleep_get_wakeup_cause();
  switch (wakeup_reason) {
    case ESP_SLEEP_WAKEUP_EXT0:     Serial.println("Wakeup caused by external signal using RTC_IO"); break;
    case ESP_SLEEP_WAKEUP_EXT1:     Serial.println("Wakeup caused by external signal using RTC_CNTL"); break;
    case ESP_SLEEP_WAKEUP_TIMER:    Serial.println("Wakeup caused by timer"); break;
    case ESP_SLEEP_WAKEUP_TOUCHPAD: Serial.println("Wakeup caused by touchpad"); break;
    case ESP_SLEEP_WAKEUP_ULP:      Serial.println("Wakeup caused by ULP program"); break;
    default:                        Serial.printf("Wakeup was not caused by deep sleep: %d\n", wakeup_reason); break;
  }
}

void setup() {
  Serial.begin(115200);
  delay(1000);  //Take some time to open up the Serial Monitor

  //Increment boot number and print it every reboot
  ++bootCount;
  Serial.println("Boot number: " + String(bootCount));

  //Print the wakeup reason for ESP32
  print_wakeup_reason();

  // EXT1 WAKEUP
  // Wake up on LOW -  BOOT Button is pulled up and it shall wake up on LOW level
  esp_sleep_enable_ext1_wakeup_io(BUTTON_PIN_BITMASK(WAKEUP_GPIO), ESP_EXT1_WAKEUP_ANY_LOW);
  gpio_pulldown_dis(WAKEUP_GPIO);
  gpio_pullup_en(WAKEUP_GPIO);  

  // Wake up on HIGH - example only
  //esp_sleep_enable_ext1_wakeup_io(BUTTON_PIN_BITMASK(WAKEUP_GPIO), ESP_EXT1_WAKEUP_ANY_HIGH);
  //gpio_pullup_dis(WAKEUP_GPIO);
  //gpio_pulldown_en(WAKEUP_GPIO);  

  //Go to sleep now
  Serial.println("Going to sleep now");
  esp_deep_sleep_start();
  Serial.println("This will never be printed");
}

void loop() {
  //This is not going to be called
}
self-assigned this
on Jun 4, 2025
VigilusPrime

VigilusPrime commented on Jun 5, 2025

@VigilusPrime
Author

@VigilusPrime - esp_deep_sleep_enable_gpio_wakeup() is not supported by ESP32-H2.

Based on https://github.com/espressif/esp-idf/blob/release/v5.4/components/esp_driver_gpio/include/driver/gpio.h#L548-L579 In order to support esp_err_t gpio_deep_sleep_wakeup_enable(gpio_num_t gpio_num, gpio_int_type_t intr_type);, the SoC must define SOC_GPIO_SUPPORT_DEEPSLEEP_WAKEUP which is not the case for ESP32-H2.

SOC_GPIO_SUPPORT_DEEPSLEEP_WAKEUP is valid for ESP32-C2, ESP32-C3, ESP32-C5, ESP32-C6, ESP32-C61 and ESP32-P4 only.

Therefore, the sketch should use EXT1 as Deepsleep wakeup source. https://docs.espressif.com/projects/esp-idf/en/v5.4.1/esp32h2/api-reference/system/sleep_modes.html

NOTE: Only GPIO7~14 on ESP32H2 can support chip deep sleep wakeup through EXT1 wake up

ESP32-H2 GPIO9 is used as BOOT Button.

This example works:

#include "driver/rtc_io.h"

#define BUTTON_PIN_BITMASK(GPIO) (1ULL << GPIO) // 2 ^ GPIO_NUMBER in hex

// ESP32-H2 can use only EXT1 as Wakeup source
// Only RTC IO are allowed - GPIO7 ~ GPIO14
#define WAKEUP_GPIO GPIO_NUM_9 // ESP32-H2 DevKit Boot Button
RTC_DATA_ATTR int bootCount = 0;

// Method to print the reason by which the SoC has been awaken from sleep
void print_wakeup_reason() {
esp_sleep_wakeup_cause_t wakeup_reason;
wakeup_reason = esp_sleep_get_wakeup_cause();
switch (wakeup_reason) {
case ESP_SLEEP_WAKEUP_EXT0: Serial.println("Wakeup caused by external signal using RTC_IO"); break;
case ESP_SLEEP_WAKEUP_EXT1: Serial.println("Wakeup caused by external signal using RTC_CNTL"); break;
case ESP_SLEEP_WAKEUP_TIMER: Serial.println("Wakeup caused by timer"); break;
case ESP_SLEEP_WAKEUP_TOUCHPAD: Serial.println("Wakeup caused by touchpad"); break;
case ESP_SLEEP_WAKEUP_ULP: Serial.println("Wakeup caused by ULP program"); break;
default: Serial.printf("Wakeup was not caused by deep sleep: %d\n", wakeup_reason); break;
}
}

void setup() {
Serial.begin(115200);
delay(1000); //Take some time to open up the Serial Monitor

//Increment boot number and print it every reboot
++bootCount;
Serial.println("Boot number: " + String(bootCount));

//Print the wakeup reason for ESP32
print_wakeup_reason();

// EXT1 WAKEUP
// Wake up on LOW - BOOT Button is pulled up and it shall wake up on LOW level
esp_sleep_enable_ext1_wakeup_io(BUTTON_PIN_BITMASK(WAKEUP_GPIO), ESP_EXT1_WAKEUP_ANY_LOW);
gpio_pulldown_dis(WAKEUP_GPIO);
gpio_pullup_en(WAKEUP_GPIO);

// Wake up on HIGH - example only
//esp_sleep_enable_ext1_wakeup_io(BUTTON_PIN_BITMASK(WAKEUP_GPIO), ESP_EXT1_WAKEUP_ANY_HIGH);
//gpio_pullup_dis(WAKEUP_GPIO);
//gpio_pulldown_en(WAKEUP_GPIO);

//Go to sleep now
Serial.println("Going to sleep now");
esp_deep_sleep_start();
Serial.println("This will never be printed");
}

void loop() {
//This is not going to be called
}

Many thanks! now it works!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

    Development

    No branches or pull requests

      Participants

      @SuGlider@P-R-O-C-H-Y@VigilusPrime

      Issue actions

        not defining esp_deep_sleep_enable_gpio_wakeup() on esp32-h2 mcu · Issue #11434 · espressif/arduino-esp32