hw: mcu: pic32mz2048efg100: Fix read of RX FIFO in hal_spi_txrx
RX FIFO was read before checking that the RX FIFO was not empty.
@@ -511,14 +511,14 @@ hal_spi_txrx(int spi_num, void *txbuf, void *rxbuf, int cnt)
SPIxBUF(spi_num) = *tx++;
}
- /* Always read RX FIFO to avoid overrun */
- rdata = SPIxBUF(spi_num);
-
- if (rx) {
/* Wait until RX FIFO is not empty */
while (SPIxSTAT(spi_num) & _SPI1STAT_SPIRBE_MASK) {
}
+ /* Always read RX FIFO to avoid overrun */
+ rdata = SPIxBUF(spi_num);
+
+ if (rx) {
*rx++ = rdata;
}
}
