Skip to content

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

@garywill

Description

@garywill

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:

while (esp_rom_get_cpu_ticks_per_us() != freq) {
vTaskDelay(1);
}

// Wait for the interface to be in the correct state.
while (self->active != active) {
MICROPY_EVENT_POLL_HOOK;
}

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions