From 6f445905267b0b1c4d1fd9f2a8ee6cb0ce6e968b Mon Sep 17 00:00:00 2001 From: Daniel Garcia Date: Wed, 16 Aug 2017 14:50:04 -0700 Subject: Pull the SPI race condition fix over to the teensy 3.6 spi code as well. Fixes #419 for teensy 3.6 as well --- platforms/arm/k66/fastspi_arm_k66.h | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/platforms/arm/k66/fastspi_arm_k66.h b/platforms/arm/k66/fastspi_arm_k66.h index b13f0ddc..7e598cff 100644 --- a/platforms/arm/k66/fastspi_arm_k66.h +++ b/platforms/arm/k66/fastspi_arm_k66.h @@ -285,13 +285,19 @@ public: 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); -- cgit v1.2.3