machine/esp32s3,esp32c3: add txStalled flag to skip USB serial spin when no host

When no USB host is reading, flushAndWait() spins 50K iterations per
FIFO-full event. With putchar calling WriteByte per byte, the cumulative
delay starves I2C and other peripherals, freezing displays.

Add a txStalled flag: the first FIFO-full triggers one flushAndWait
attempt. If it fails (no host), txStalled is set and all subsequent
writes return immediately with no spin — just a register read and a
bool check. When a host reconnects, SERIAL_IN_EP_DATA_FREE goes back
to 1, bypassing the stall path and clearing the flag automatically.
This commit is contained in:
deadprogram
2026-04-14 08:45:00 +02:00
committed by Ron Evans
parent 894839484c
commit 0e84235f9a
4 changed files with 124 additions and 42 deletions
+1
View File
@@ -151,6 +151,7 @@ func initTimerInterrupt() {
// sleepTicks spins until the given number of ticks have elapsed, using the
// TIMG0 alarm interrupt to avoid busy-waiting for the entire duration.
func sleepTicks(d timeUnit) {
machine.FlushSerial()
target := ticks() + d
for ticks() < target {
// Set the alarm to fire at the target tick count (or as close
+1
View File
@@ -110,6 +110,7 @@ func initTimerInterrupt() {
// sleepTicks spins until the given number of ticks have elapsed, using the
// TIMG0 alarm interrupt to avoid busy-waiting for the entire duration.
func sleepTicks(d timeUnit) {
machine.FlushSerial()
target := ticks() + d
for ticks() < target {
// Set the alarm to fire at the target tick count.