RIOT icon indicating copy to clipboard operation
RIOT copied to clipboard

cpu/esp32: extend GPIO wake-up from deep sleep

Open gschorcht opened this issue 3 years ago • 2 comments

Contribution description

This PR extends the GPIO wake-up logic from deep sleep.

Depending on SoC capabilities, ESP32x SoC variants support different logical combinations of GPIO levels to wake-up from deep sleep. This change is necessary for example necessary to use GPIOs for waking up ESP32-C3 from deep sleep.

Testing procedure

Without this PR, the compilation for all ESP_PM_WUP_LEVEL values:

CFLAGS='-DESP_PM_WUP_PINS=GPIO8 -DESP_PM_WUP_LEVEL=ESP_PM_WUP_PINS_ANY_HIGH \
        -DESP_PM_WUP_UART0=6 -DESP_PM_GPIO_HOLD' make BOARD=esp32c3-devkit -C tests/periph_pm

fail with implicit declaration of function 'esp_sleep_enable_ext1_wakeup'

With this PR

CFLAGS='-DESP_PM_WUP_PINS=GPIO8 -DESP_PM_WUP_LEVEL=ESP_PM_WUP_PINS_ANY_HIGH \
        -DESP_PM_WUP_UART0=6 -DESP_PM_GPIO_HOLD' make BOARD=esp32c3-devkit -C tests/periph_pm

and

CFLAGS='-DESP_PM_WUP_PINS=GPIO8 -DESP_PM_WUP_LEVEL=ESP_PM_WUP_PINS_ANY_LOW \
        -DESP_PM_WUP_UART0=6 -DESP_PM_GPIO_HOLD' make BOARD=esp32c3-devkit -C tests/periph_pm

compile successful.

CFLAGS='-DESP_PM_WUP_PINS=GPIO8 -DESP_PM_WUP_LEVEL=ESP_PM_WUP_PINS_ALL_LOW \
        -DESP_PM_WUP_UART0=6 -DESP_PM_GPIO_HOLD' make BOARD=esp32c3-devkit -C tests/periph_pm

give the error message ESP32x SoC does not support this ESP_PM_WUP_LEVEL.

Issues/PRs references

gschorcht avatar Aug 07 '22 06:08 gschorcht

That API is rather bespoke.

On SAM D5x/E5x I had the same problem, only RTC tamper pins can wake the CPU from Deep Sleep. But I just added this to gpio_init_int(), so when an interrupt was configured on the pin, the RTC pin is configured before entering Deep Sleep.

Would this also make sense for esp32? Then apps could be portable across architectures in waking up from Deep Sleep.

benpicco avatar Aug 09 '22 20:08 benpicco

Would this also make sense for esp32?

Something like this would be possible, but the behavior and logic of waking up from deep sleep is different from interruptions. For ESP32x SoCs you can't define egde triggered wakeups but only level triggered.

Even worse is that you can only define that

  • either any pin must be HIGH (ESP_PM_WUP_PINS_ALL_LOW) to wake up
  • or any pin (ESP_PM_WUP_PINS_ANY_LOW, ESP32-C3 only) or all pins must be LOW (ESP_PM_WUP_PINS_ALL_LOW, ESP32, ESP32-S2, ESP32-S3).

The combination of HIGH and LOW is not possible. In particular the case ESP_PM_WUP_PINS_ALL_LOW is a problem because interrupt signals are usually LOW active.

So the logical behavior is completely different from the interrupts when different levels or LOW level are used. Maybe we should better leave it as a dedicated option to be configured.

gschorcht avatar Aug 10 '22 05:08 gschorcht