Skip to content

Commit 00815f2

Browse files
rsaxvcigrr
authored andcommitted
Manually manage FIFO volatility
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;
1 parent c07c8dc commit 00815f2

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

libraries/SPI/SPI.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,7 @@ void SPIClass::writeBytes_(uint8_t * data, uint8_t size) {
398398
// Set Bits to transfer
399399
setDataBits(size * 8);
400400

401-
volatile uint32_t * fifoPtr = &SPI1W0;
401+
uint32_t * fifoPtr = (uint32_t*)&SPI1W0;
402402
uint32_t * dataPtr = (uint32_t*) data;
403403
uint8_t dataSize = ((size + 3) / 4);
404404

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

411+
__sync_synchronize();
411412
SPI1CMD |= SPIBUSY;
412413
while(SPI1CMD & SPIBUSY) {}
413414
}

0 commit comments

Comments
 (0)