mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-05 19:43:44 +00:00
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:
@@ -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
|
||||
|
||||
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user