Skip to content

Commit 2f983de

Browse files
Handke SPISlave with no output data ever written (#3069)
Fixes #3068. The SPISlave TX-FIFO IRQ would infinitely try to fill the FIFO as soon as IRQs were enabled, but in the case when the app never sent any data this would cause an infinite loop in the IRQ handler. Now abort if we don't have any data, even if there is space in the FIFO.
1 parent 9e49c58 commit 2f983de

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

libraries/SPISlave/src/SPISlave.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,14 +167,14 @@ void SPISlaveClass::_handleIRQ() {
167167
_recvCB(buff, cnt);
168168
}
169169
// Attempt to send as many bytes to the TX FIFO as we have/are free
170-
while (spi_is_writable(_spi)) {
170+
do {
171171
for (; _dataLeft && spi_is_writable(_spi); _dataLeft--) {
172172
spi_get_hw(_spi)->dr = *(_dataOut++);
173173
}
174174
if (!_dataLeft && _sentCB) {
175175
_sentCB();
176176
}
177-
}
177+
} while (spi_is_writable(_spi) & _dataLeft);
178178
// Disable the TX FIFO IRQ if there is still no data to send or we'd always be stuck in an IRQ
179179
// Will be re-enabled once user does a setData
180180
if (!_dataLeft) {

0 commit comments

Comments
 (0)