Skip to content

Commit ff64b2d

Browse files
Make SPI receive buffer 32-bit aligned on 8266
The ESP8266 SPI implementation needs a 4-byte aligned read buffer, same as for transmit. Fix the ESP8266 SPI driver wrapper to ensure this alignment occurs.
1 parent 7746c9a commit ff64b2d

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/SpiDriver/SdSpiESP8266.cpp

+6-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,12 @@ uint8_t SdSpiAltDriver::receive() {
6767
* \return Zero for no error or nonzero error code.
6868
*/
6969
uint8_t SdSpiAltDriver::receive(uint8_t* buf, size_t n) {
70-
// Works without 32-bit alignment of buf.
70+
// Adjust to 32-bit alignment.
71+
while ((reinterpret_cast<uintptr_t>(buf) & 0X3) && n) {
72+
*buf++ = SPI.transfer(0xff);
73+
n--;
74+
}
75+
// Buff now 32-bit aligned
7176
SPI.transferBytes(0, buf, n);
7277
return 0;
7378
}

0 commit comments

Comments
 (0)