Commit 41e8ca7
committed
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 #30711 parent bdea44d commit 41e8ca7
1 file changed
Lines changed: 8 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
583 | 583 | | |
584 | 584 | | |
585 | 585 | | |
| 586 | + | |
| 587 | + | |
| 588 | + | |
| 589 | + | |
| 590 | + | |
| 591 | + | |
| 592 | + | |
| 593 | + | |
586 | 594 | | |
587 | 595 | | |
588 | 596 | | |
| |||
0 commit comments