From 77c9734cf8d085ddc724286bc63fc3fa975b4b13 Mon Sep 17 00:00:00 2001 From: Robert Fisk Date: Sun, 15 Nov 2015 00:28:45 +1300 Subject: [PATCH] Apply v1.0's upstream DMA workaround to v0.9. So it seems that under some circumstances the 405 is equally buggy as the 401! Work around an intermittent stall/timeout by busy-waiting Upstream's packet length transmission and reception, instead of DMA-ing it like the packet body. Ugh... --- .../STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_spi.h | 2 ++ .../STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_spi.c | 1 - Upstream/Src/upstream_spi.c | 14 ++++++++++---- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/Upstream/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_spi.h b/Upstream/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_spi.h index dfdc0c5..0e86632 100644 --- a/Upstream/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_spi.h +++ b/Upstream/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_spi.h @@ -302,6 +302,8 @@ typedef struct __SPI_HandleTypeDef * @} */ +#define SPI_TIMEOUT_VALUE 2 + /** * @} */ diff --git a/Upstream/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_spi.c b/Upstream/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_spi.c index d412fdc..be5326a 100644 --- a/Upstream/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_spi.c +++ b/Upstream/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_spi.c @@ -104,7 +104,6 @@ /* Private typedef -----------------------------------------------------------*/ /* Private define ------------------------------------------------------------*/ -#define SPI_TIMEOUT_VALUE 2 /* Private macro -------------------------------------------------------------*/ /* Private variables ---------------------------------------------------------*/ /* Private function prototypes -----------------------------------------------*/ diff --git a/Upstream/Src/upstream_spi.c b/Upstream/Src/upstream_spi.c index caf20b1..e4787d1 100644 --- a/Upstream/Src/upstream_spi.c +++ b/Upstream/Src/upstream_spi.c @@ -442,13 +442,16 @@ void Upstream_BeginTransmitPacketSize(void) { UpstreamInterfaceState = UPSTREAM_INTERFACE_TX_SIZE; SPI1_NSS_ASSERT; - if (HAL_SPI_TransmitReceive_DMA(&Hspi1, + if (HAL_SPI_TransmitReceive(&Hspi1, (uint8_t*)&CurrentWorkingPacket->Length16, (uint8_t*)&TemporaryIncomingPacketLength, - 2) != HAL_OK) //We only need to write one word, but the peripheral library freaks out... + 2, + SPI_TIMEOUT_VALUE) != HAL_OK) //We only need to write one word, but the peripheral library freaks out... { UPSTREAM_SPI_FREAKOUT; } + + HAL_SPI_TxRxCpltCallback(&Hspi1); } @@ -485,13 +488,16 @@ void Upstream_BeginReceivePacketSize(UpstreamPacketTypeDef* freePacket) CurrentWorkingPacket = freePacket; CurrentWorkingPacket->Length16 = 0; //Our RX buffer is used by HAL_SPI_TransmitReceive_DMA as dummy TX data, we set Length to 0 so downstream will know this is a dummy packet. SPI1_NSS_ASSERT; - if (HAL_SPI_TransmitReceive_DMA(&Hspi1, + if (HAL_SPI_TransmitReceive(&Hspi1, (uint8_t*)&CurrentWorkingPacket->Length16, (uint8_t*)&CurrentWorkingPacket->Length16, - 2) != HAL_OK) //We only need to write one word, but the peripheral library freaks out... + 2, + SPI_TIMEOUT_VALUE) != HAL_OK) //We only need to write one word, but the peripheral library freaks out... { UPSTREAM_SPI_FREAKOUT; } + + HAL_SPI_TxRxCpltCallback(&Hspi1); }