← index #5651PR #8708
Likely Duplicate · medium · value 2.387
QUERY · ISSUE

ESP32: deep sleep seems to cut clock to ULP processor

openby flo-rianopened 2020-02-16updated 2025-09-23
port-esp32

It seems like going to deep sleep stops the ULP processor. I uploaded a counter code to the ULP and it counts nicely as long as main CPUs running. When going to deep sleep counting stops but the counter value remains so the ULP was not reset or memory erased. After coming back from deep sleep counting works again.

As a side note: I would like to suggest to also add the ULP as a wakeup source in the esp32 package (in addition to the EXT, timer and touch options).

CANDIDATE · PULL REQUEST

esp32: Allow ULP to wake main CPU from deepsleep.

closedby cwaltheropened 2022-05-28updated 2022-06-23
port-esp32

The attached commit adds the function wake_on_ulp() to the esp32 module, giving access to ESP-IDF function esp_sleep_enable_ulp_wakeup(), which is needed to allow the ULP co-processor to wake the main CPU from deep sleep.

Tested on a UM_TINYPICO board, built with ESP-IDF v4.2.2.

Steps to reproduce:

Run the following on the REPL:

>>> b = b'ulp\x00\x0c\x00\x1c\x00\x00\x00\x00\x00\x00\x00@t\xff\xff\x00@\xff\xff\x00@\x10\x00\x00t\xff\x00\x06\x85\x01\x00\x00\x90\x00\x00\x00\xb0'
>>> import esp32, machine
>>> ulp = esp32.ULP()
>>> ulp.load_binary(0, b); ulp.run(0); machine.deepsleep(10000)

Actual and expected result (before and after): The processor wakes back up after 10 seconds (deepsleep timer), even though the ULP has tried to wake it up earlier.

After: Run the same commands, but with the last line changed to

ulp.load_binary(0, b); ulp.run(0); esp32.wake_on_ulp(True); machine.deepsleep(10000)

Expected result: The processor wakes back up after around 4 seconds, when the ULP executes the wake instruction.

The ULP program above is the compiled form of

.text
.global main
main:
	stage_rst
loop:
	wait 65535
	wait 65535
	stage_inc 1
	jumps loop, 255, lt
	wake
	halt

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