-
Notifications
You must be signed in to change notification settings - Fork 7.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Serial.print() in WiFi event handler can hang ESP32-S2 (repro case included) #10137
Comments
Does it work if you use ets_printf instead? |
Thank you, @egnor! Issue confirmed. We will investigate it. The issue seems to be some problem with concurrency related to USB OTG state in TinyUSB (S2 and S3 using OTG UB Mode). Up on my testing, the issue doesn't affect the UART and also not the HW Serial JTAG USB CDC. In the meanwhile, if necessary, you can use logging (like |
It seems that this is an exclusive issue with the S2 USB OTG with CDC. |
|
Yes, it also works fine. Thank you @lbernstone. #include <Arduino.h>
#include <WiFi.h>
#include "rom/ets_sys.h"
constexpr char const* WIFI_SSID = "oneruling classic";
constexpr char const* WIFI_PASSWORD = "oneruling";
static void on_event(arduino_event_id_t id) {
// ets_printf() replaces Serial.print(".") only when Serial.setDebutOutput(true) is executed
for (int i = 0; i < 80; ++i) ets_printf(".");
ets_printf("\r\n"); // replaces Serial.println();
}
void setup() {
Serial.begin();
Serial.setDebugOutput(true);
for (int n = 5; n > 0; --n) {
Serial.print("SETUP COUNTDOWN: ");
Serial.println(n);
delay(100);
}
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);
} |
Yeah, I tried using |
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
) callsSerial.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.)
Debug Message
(and then it hangs)
I have checked existing issues, online documentation and the Troubleshooting Guide
The text was updated successfully, but these errors were encountered: