micropython / micropython/micropython

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

Open
#18,427 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug port-esp32
Dominant language
C
Stars
22.1k
Forks
9k
Avg merge
6d 4h
Merged PRs (30d)
16

Description

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with ports/esp32/modmachine.c around lines 128-130 and ports/esp32/network_wlan.c around lines 291-294, then reproduce the two frequency/Wi-Fi orderings on an ESP32 with MicroPython v1.26.1. Check the Espressif APB-clock constraint and determine the expected safeguard behavior; done means the incompatible configuration no longer freezes MicroPython and the relevant behavior is covered by tests or documented validation.

Written by the indexing model from the issue text.

Assessment

Tech stack
c, python
Domain
embedded-iot, operating-systems
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.