From da849318b30180153e3d63c16c1a9da909dcb7e8 Mon Sep 17 00:00:00 2001 From: Martin Luessi Date: Sun, 26 Dec 2021 07:35:18 -0800 Subject: [PATCH] Fix SPI sequencing in spiInternalReadWriteBufPolled for H7 --- src/main/drivers/bus_spi_ll.c | 26 ++++++++++---------------- 1 file changed, 10 insertions(+), 16 deletions(-) diff --git a/src/main/drivers/bus_spi_ll.c b/src/main/drivers/bus_spi_ll.c index f8c2d2733..3b02f90c9 100644 --- a/src/main/drivers/bus_spi_ll.c +++ b/src/main/drivers/bus_spi_ll.c @@ -225,26 +225,20 @@ void spiInternalResetStream(dmaChannelDescriptor_t *descriptor) static bool spiInternalReadWriteBufPolled(SPI_TypeDef *instance, const uint8_t *txData, uint8_t *rxData, int len) { #if defined(STM32H7) - int txLen = len; - int rxLen = len; - - LL_SPI_SetTransferSize(instance, txLen); + LL_SPI_SetTransferSize(instance, len); LL_SPI_Enable(instance); LL_SPI_StartMasterTransfer(instance); - while (txLen || rxLen) { - if (txLen && LL_SPI_IsActiveFlag_TXP(instance)) { - uint8_t b = txData ? *(txData++) : 0xFF; - LL_SPI_TransmitData8(instance, b); - txLen--; - } + while (len) { + while (!LL_SPI_IsActiveFlag_TXP(instance)); + uint8_t b = txData ? *(txData++) : 0xFF; + LL_SPI_TransmitData8(instance, b); - if (rxLen && LL_SPI_IsActiveFlag_RXP(instance)) { - uint8_t b = LL_SPI_ReceiveData8(instance); - if (rxData) { - *(rxData++) = b; - } - rxLen--; + while (!LL_SPI_IsActiveFlag_RXP(instance)); + b = LL_SPI_ReceiveData8(instance); + if (rxData) { + *(rxData++) = b; } + --len; } while (!LL_SPI_IsActiveFlag_EOT(instance)); LL_SPI_ClearFlag_TXTF(instance); -- 2.11.4.GIT