From 2218a05652ac9890cbef742f5c6d306a8b4b8902 Mon Sep 17 00:00:00 2001 From: Martino Facchin Date: Thu, 7 Sep 2017 17:21:28 +0200 Subject: [PATCH] Avoid stalling if uart buffer becomes full --- cores/arduino/Uart.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/cores/arduino/Uart.cpp b/cores/arduino/Uart.cpp index adc73146f..16afe4e41 100644 --- a/cores/arduino/Uart.cpp +++ b/cores/arduino/Uart.cpp @@ -110,7 +110,11 @@ size_t Uart::write(const uint8_t data) if (sercom->isDataRegisterEmptyUART() && txBuffer.available() == 0) { sercom->writeDataUART(data); } else { - while(txBuffer.isFull()); // spin lock until a spot opens up in the buffer + while (txBuffer.isFull()) { + // Pretend an interrupt has happened and + // call the handler to free up space for us. + IrqHandler(); + }; txBuffer.store_char(data);