You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 2420b31
Browse filesBrowse the repository at this point in the historyBrowse files
fix(Serial): Uart::write() must not spin when begin() failed
If Serial.begin(baud) fails during hardware init (e.g. an LPUART
clocked from LSE can't reach the requested baud rate), uart_init()
returns false and _ready is set to false -- but Uart::write() never
checks _ready before entering its transmit path.
Uart::write(const uint8_t*, size_t) contains:
while (!availableForWrite()) {
// nop, the interrupt handler will free up space for us
}
Since the hardware was never actually brought up, the TX interrupt
this loop waits on never fires, so once the 63-byte TX ring buffer
fills up (a few Serial.print() calls after a failed begin()), this
spins forever and the MCU deadlocks permanently.
Fix: return 0 immediately if !_ready, before touching the buffer or
entering the wait loop, using the same _ready accessor already used
elsewhere in this file (see Uart::begin(), which sets it, and the
existing operator bool()-style accessor in Serial.h). write(uint8_t)
needs no separate guard since it already delegates to this overload.
Fixes#3071
0 commit comments