SPIClass::begin() may leave the SPI peripheral uninitialized when the
requested settings are equal to the internally cached default SPISettings.
In this case, configSpi() does not call spi_init(). A subsequent transfer
using the default SPI configuration may therefore fail or reach an
uninitialized peripheral.
Calling beginTransaction() with different SPI settings can mask the issue,
because it causes spi_init() to be called.
This regression was exposed during SPI3 loopback validation on a Seeed XIAO
STM32C5, but the root cause appears to be in the common SPI implementation and
is not board-specific.
A related fix is proposed in PR #3049:
#3049
To Reproduce
Minimal sketch:
#include <SPI.h>
void setup()
{
SPI.begin();
SPI.beginTransaction(SPISettings(4000000, MSBFIRST, SPI_MODE0));
uint8_t value = SPI.transfer(0x00);
SPI.endTransaction();
}
void loop()
{
}
SPIClass::begin()may leave the SPI peripheral uninitialized when therequested settings are equal to the internally cached default
SPISettings.In this case,
configSpi()does not callspi_init(). A subsequent transferusing the default SPI configuration may therefore fail or reach an
uninitialized peripheral.
Calling
beginTransaction()with different SPI settings can mask the issue,because it causes
spi_init()to be called.This regression was exposed during SPI3 loopback validation on a Seeed XIAO
STM32C5, but the root cause appears to be in the common SPI implementation and
is not board-specific.
A related fix is proposed in PR #3049:
#3049
To Reproduce
Minimal sketch: