← index #17334PR #16883
Related · high · value 0.751
QUERY · ISSUE

ESP32-C6: WAKEUP_ALL_LOW causes GPIO pin to be stuck upon waking from deeepsleep

openby ned-pcsopened 2025-05-21updated 2025-05-21
bug

Port, board and/or hardware

ESP32_C6_GENERIC, Seeed Studio XIAO ESP32-C6

MicroPython version

MicroPython v1.25.0 on 2025-04-15; ESP32C6 module with ESP32C6

Reproduction

  1. Copy the code below into main.py on an ESP32-C6 board.
  2. Reset the board.
from machine import Pin, deepsleep
from esp32 import wake_on_ext1, WAKEUP_ALL_LOW 
from time import sleep_ms

BUTTON_PIN = 0  # must be RTC-capable pin.
LED_PIN = 15 # XIAO ESP32-C6 User LED pin, active LOW

sleep_ms(1000) # wait for button to be released

button = Pin(BUTTON_PIN, Pin.IN, Pin.PULL_UP)
led = Pin(LED_PIN, Pin.OUT, value=1)  # active low

def blink_led(period_ms):
    led.value(0)  # turn on LED
    sleep_ms(period_ms)
    led.value(1)  # turn off LED

blink_led(500)

if button.value() == 1:
    wake_on_ext1([button], WAKEUP_ALL_LOW)
    deepsleep()
else:
    print("Button is pressed. Not going to sleep.")
    while True:
        sleep_ms(100)
        blink_led(100)

Expected behaviour

Expected to long-blink the LED once after reset.
If pin GPIO 0 is briefly connected to GND you should get another single blink.

Observed behaviour

The LED long-blinks once, then again after 1 second, then flashes rapidly, indicating that pin 0 is stuck LOW.

Interrupting with mpremote repl you can examine the state of button:

>>> button.value()
0
>>>

Additional Information

If you use esp32.WAKEUP_ANY_HIGH (and Pin.PULL_DOWN) it works correctly.

Also, wake_on_ext0(button, WAKEUP_ALL_LOW) doesn't wake up on the GPIO going LOW.

Code of Conduct

Yes, I agree

CANDIDATE · PULL REQUEST

Support wakeup gpio source of ESP32C3 and I was tuned wakeup source one by one each soc.

closedby pop-aruaruopened 2025-03-09updated 2025-03-09

<!-- Thanks for submitting a Pull Request! We appreciate you spending the
time to improve MicroPython. Please provide enough information so that
others can review your Pull Request.

 Before submitting, please read:
 https://github.com/micropython/micropython/blob/master/CODEOFCONDUCT.md
 https://github.com/micropython/micropython/wiki/ContributorGuidelines

 Please check any CI failures that appear after your Pull Request is opened.

-->

Summary

I was add deepsleep wakeup by gpio on ESP32C3.

new function and const in esp32 module:

  • wake_on_gpio([machine.Pin],level])

level

  • WAKEUP_GPIO_HIGH
  • WAKEUP_GPIO_LOW

almost same esp32.wake_on_ext1 and esp32.wake_on_ext0

And I was tuned struct machine_rtc_config_t in machine_rtc.h file by soc selector in ports/esp32:

  • SOC_GPIO_SUPPORT_DEEPSLEEP_WAKEUP
  • SOC_PM_SUPPORT_EXT0_WAKEUP
  • SOC_PM_SUPPORT_EXT1_WAKEUP
  • SOC_ULP_SUPPORTED
  • SOC_TOUCH_SENSOR_SUPPORTED

And I also changed some files that came with it.

Testing

  • build test:
    build-ESP32_GENERIC
    build-ESP32_GENERIC_C3
    build-ESP32_GENERIC_C6
    build-ESP32_GENERIC_S2
    build-ESP32_GENERIC_S3

ESP_IDF_VERSION=5.2
on MAC-OS

  • deepsleep wakeup test:
    ESP32_GENERIC_C3 on seeed xiao-esp32c3

test micropython code

import time
import time
import esp32
from machine import Pin,deepsleep,PWM

pwm = PWM(5,freq=50)
hz0=400
pwm.duty_u16(0x800)
pwm.freq(hz0)
time.sleep(10) # you can connect while 10sec.
a=Pin(2,Pin.IN,pull=Pin.PULL_UP,hold=True)
b=Pin(3,Pin.IN,pull=Pin.PULL_UP,hold=True)
c=Pin(4,Pin.IN,pull=Pin.PULL_UP,hold=True)
esp32.wake_on_gpio([b,c],esp32.WAKEUP_GPIO_HIGH)
esp32.wake_on_gpio([a],esp32.WAKEUP_GPIO_LOW)
deepsleep(60_000) # 60sec
# deepsleep() # forever 

Trade-offs and Alternatives

Depending on the soc feature, the functions and constants available to the micropython esp32 module change.
Therefore, the python code becomes more device-dependent.

<!-- If the Pull Request has some negative impact (i.e. increased code size)
then please explain why you think the trade-off improvement is worth it.
If you can think of alternative ways to do this, please explain that here too.

 Delete this heading if not relevant (i.e. small fixes) -->

Keyboard

j / / n
next pair
k / / p
previous pair
1 / / h
show query pane
2 / / l
show candidate pane
c
copy suggested comment
r
toggle reasoning
g i
go to index
?
show this help
esc
close overlays

press ? or esc to close

copied