Skip to content

Serial.print() in WiFi event handler can hang ESP32-S2 (repro case included) #10137

@egnor

Description

@egnor

Board & Hardware Description

I'm using my own ESP32-S2 board, but probably any ESP32-S2-based board with USB would reproduce this. (I can pick up a generic dev board and try there if desired.) It's probably important to be using USB for bootloading and console output.

Version

v3.0.4

IDE Name

arduino-cli

Operating System

Ubuntu 24.04 (probably doesn't matter tho)

Flash frequency

default

PSRAM enabled

yes

Upload speed

default

Description

When an event handler on the ESP-IDF default event loop (such as registered by WiFi.onEvent) calls Serial.print() too often, the CPU locks up and stops responding to anything.

Sketch

(Edit the wifi access point constants obviously! -- it might be important that the wifi actually connects.)

#include <Arduino.h>
#include <WiFi.h>

constexpr char const* WIFI_SSID = "oneruling classic";
constexpr char const* WIFI_PASSWORD = "oneruling";

static void on_event(arduino_event_id_t id) {
  for (int i = 0; i < 80; ++i) Serial.print(".");
  Serial.println();
}

void setup() {
  Serial.begin(115200);
  Serial.setDebugOutput(true);
  for (int n = 5; n > 0; --n) {
    Serial.print("SETUP COUNTDOWN: ");
    Serial.println(n);
    delay(1000);
  }

  WiFi.onEvent(on_event);
  WiFi.begin(WIFI_SSID, WIFI_PASSWORD);  
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.println("Waiting for wifi...");
  }
}

void loop() {
  Serial.println("LOOP");
  delay(500);
}

Debug Message

SETUP COUNTDOWN: 5
SETUP COUNTDOWN: 4
SETUP COUNTDOWN: 3
SETUP COUNTDOWN: 2
SETUP COUNTDOWN: 1
.............

(and then it hangs)

I have checked existing issues, online documentation and the Troubleshooting Guide

  • I confirm I have checked existing issues, online documentation and Troubleshooting guide.

Metadata

Metadata

Assignees

Labels

Chip: ESP32-S2Issue is related to support of ESP32-S2 ChipStatus: Awaiting ResponseAwaiting a response from the author

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions