AnsweredAssumed Answered

Race condition in the LPC5410X SPI master driver

Question asked by Tim Carney on Jan 29, 2018
Latest reply on Feb 2, 2018 by Tim Carney

While developing using the LPC5410X SPI master driver, I have discovered a race condition.


The initial SPI transfer is initiated by calling the interrupt handler (Chip_SPIM_XferHandler) from the application. When sending data, the TXDAT register is set with the current byte to be sent and then the index into the transmit buffer is incremented.


It is possible that the SPI_INTENSET_SSAEN interrupt can occur between setting the TXDAT register and incrementing the index into the transmit buffer. When this occurs, the SPI driver will send the same byte twice (once called from the application and the second called in the ISR).


For our application, I have modified the SPI driver to increment the pointer into the transmit buffer prior to setting the TXDAT register. While this seems to get the driver to behave as our application needs it to, I'm not comfortable that this is the correct solution, especially for applications that may be using the SPIM_XFER_OPTION_EOT option.