← index #18427Issue #16602
Off-topic · high · value 0.316
QUERY · ISSUE

esp32: Consider CPU frequency constraints when Wi-Fi/BT is enabled

openby garywillopened 2025-11-16updated 2025-11-16
bug

Port, board and/or hardware

esp32

MicroPython version

v1.26.1

Reproduction

I’ve tested this myself:

  1. Turn on Wi-Fi

  2. machine.freq(40_000_000)
    MPY freezes

  3. freq(40_000_000) first

  4. wlan.active(True)
    MPY freezes

Expected behaviour

Espressif’s docs do say that APB clock must be ≥80 MHz when wireless is on, and APB = CPU freq when it’s under 80 MHz

Observed behaviour

MPY freezes when cpu freq not compatitable with wireless module.

I think it stucks here:
https://github.com/micropython/micropython/blob/27544a2d81da5b0d804a932d98d680f121a22b8f/ports/esp32/modmachine.c#L128-L130

https://github.com/micropython/micropython/blob/27544a2d81da5b0d804a932d98d680f121a22b8f/ports/esp32/network_wlan.c#L291-L294

Additional Information

Would it be possible to add a safeguard in MPY? For example:
If Wi-Fi or BLE is active, set a min allowed freq (raise an exception or warn if user tries to go lower)
When CPU freq already low, don't allow to enable wifi

Some tips from web:

CPU Frequency Wi-Fi (STA/AP) BLE (Low Energy) Bluetooth Classic (A2DP, SPP, etc.)
≥ 160 MHz ✅ Stable ✅ Stable ✅ Recommended / Stable
80 – 159 MHz ✅ Generally OK ✅ Generally OK ⚠️ May be unstable (not recommended)
< 80 MHz ❌ Unreliable / Hangs ❌ Unreliable / Hangs ❌ Likely to fail

Code of Conduct

Yes, I agree

CANDIDATE · ISSUE

time.ticks_cpu() weird overflow on esp32

closedby 0wwafaopened 2025-01-17updated 2025-01-19

Port, board and/or hardware

esp32

MicroPython version

MicroPython v1.24.1 on 2024-11-29; Generic ESP32 module with ESP32

Reproduction

def test(x,freq):
   machine.freq(freq*1000000)
   s=time.ticks_cpu()
   time.sleep(x)
   d=time.ticks_diff(time.ticks_cpu(),s)
   if d<0: d+=1073741824 #ticks overflow at 2^30
   print(d/(freq*1000000))

Expected behaviour

it seems that time.ticks_cpu() is 30 bit signed.

it overflows at 1073741824 (2^30)

Observed behaviour

shouldn't it be 2^31 or just a 32 bit INT?

is there a reason for that?

because of this the maximum elapsed ticks measurable are:

53.6870912 seconds @ 20 Mhz
26.8435456 seconds @ 40 Mhz
13.4217728 seconds @ 80 Mhz
6.7108864 seconds @ 160 Mhz
4.47392426 seconds @ 240 Mhz

please if possible, express ticks as a 32 bit integer

Additional Information

No, I've provided everything above.

Code of Conduct

Yes, I agree

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