Skip to content

Commit

Permalink
Pull the SPI race condition fix over to the teensy 3.6 spi code as we…
Browse files Browse the repository at this point in the history
…ll. Fixes #419 for teensy 3.6 as well
  • Loading branch information
focalintent committed Aug 16, 2017
1 parent 06521a4 commit 6f44590
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions platforms/arm/k66/fastspi_arm_k66.h
Expand Up @@ -285,13 +285,19 @@ class ARMHardwareSPIOutput {

static void waitFully() __attribute__((always_inline)) {
// Wait for the last byte to get shifted into the register
cli();
while( (SPIX.SR & 0xF000) > 0) {
// reset the TCF flag
SPIX.SR |= SPI_SR_TCF;
}
sei();

bool empty = false;

do {
cli();
if ((SPIX.SR & 0xF000) > 0) {
// reset the TCF flag
SPIX.SR |= SPI_SR_TCF;
} else {
empty = true;
}
sei();
} while (!empty);

// wait for the TCF flag to get set
while (!(SPIX.SR & SPI_SR_TCF));
SPIX.SR |= (SPI_SR_TCF | SPI_SR_EOQF);
Expand Down

0 comments on commit 6f44590

Please sign in to comment.