Skip to content

Commit

Permalink
Manually manage FIFO volatility
Browse files Browse the repository at this point in the history
Replace volatile with properly placed __sync_synchronize

SPI1W0 is volatile, but when writing multiple words
to the FIFO (which is really just a piece of SRAM),
we don't need to worry about write ordering. We only
need worry about write ordering such that all FIFO
words are written completely before HSPI is told to
use FIFO by setting SPI1CMD |= SPIBUSY;
  • Loading branch information
rsaxvc authored and igrr committed Jun 7, 2017
1 parent c07c8dc commit 00815f2
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion libraries/SPI/SPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ void SPIClass::writeBytes_(uint8_t * data, uint8_t size) {
// Set Bits to transfer
setDataBits(size * 8);

volatile uint32_t * fifoPtr = &SPI1W0;
uint32_t * fifoPtr = (uint32_t*)&SPI1W0;
uint32_t * dataPtr = (uint32_t*) data;
uint8_t dataSize = ((size + 3) / 4);

Expand All @@ -408,6 +408,7 @@ void SPIClass::writeBytes_(uint8_t * data, uint8_t size) {
fifoPtr++;
}

__sync_synchronize();
SPI1CMD |= SPIBUSY;
while(SPI1CMD & SPIBUSY) {}
}
Expand Down

0 comments on commit 00815f2

Please sign in to comment.