stm32: Clear SPE flag on a change to SPI CR1 register

The stm32 specs indicate that the SPE bit must be cleared before
changing the CPHA or CPOL bits.

Reported by @cbc02009 and @bigtreetech.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
Kevin O'Connor 2022-02-10 17:20:49 -05:00
parent 99d55185a2
commit e3cbe7ea36
1 changed files with 6 additions and 0 deletions

View File

@ -100,6 +100,12 @@ void
spi_prepare(struct spi_config config) spi_prepare(struct spi_config config)
{ {
SPI_TypeDef *spi = config.spi; SPI_TypeDef *spi = config.spi;
uint32_t cr1 = spi->CR1;
if (cr1 == config.spi_cr1)
return;
// The SPE bit must be disabled before changing CPOL/CPHA bits
spi->CR1 = cr1 & ~SPI_CR1_SPE;
spi->CR1; // Force flush of previous write
spi->CR1 = config.spi_cr1; spi->CR1 = config.spi_cr1;
} }