Skip to content

Commit

Permalink
Make slow SPI speeds work on the auxiliary SPI master
Browse files Browse the repository at this point in the history
The auxiliary SPI driver could get desynchronized with the hardware
when reading using low bit rates.  It was only looking to see if the
TX queue was empty, which doesn't actually tell you if the hardware is
done doing stuff or not.
  • Loading branch information
jpieper committed Sep 10, 2021
1 parent 1195485 commit d70dda2
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion lib/cpp/mjbots/pi3hat/pi3hat.cc
Original file line number Diff line number Diff line change
Expand Up @@ -631,7 +631,13 @@ class AuxSpi {
spi_->io = value;
}

while ((spi_->stat & AUXSPI_STAT_TX_EMPTY) == 0);
while (true) {
const auto stat = spi_->stat;
if ((stat & AUXSPI_STAT_BUSY) == 0 &&
(stat & AUXSPI_STAT_TX_EMPTY) != 0) {
break;
}
}

if (size == 0) { return; }

Expand Down

0 comments on commit d70dda2

Please sign in to comment.