Skip to content

Commit 53a8aeb

Browse files
committed
stmhal: Fix slow SPI DMA transfers by removing wfi from DMA wait loop.
Addresses issue adafruit#1268.
1 parent 80f638f commit 53a8aeb

1 file changed

Lines changed: 3 additions & 1 deletion

File tree

stmhal/spi.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,12 +290,14 @@ void spi_deinit(SPI_HandleTypeDef *spi) {
290290
}
291291

292292
STATIC HAL_StatusTypeDef spi_wait_dma_finished(SPI_HandleTypeDef *spi, uint32_t timeout) {
293+
// Note: we can't use WFI to idle in this loop because the DMA completion
294+
// interrupt may occur before the WFI. Hence we miss it and have to wait
295+
// until the next sys-tick (up to 1ms).
293296
uint32_t start = HAL_GetTick();
294297
while (HAL_SPI_GetState(spi) != HAL_SPI_STATE_READY) {
295298
if (HAL_GetTick() - start >= timeout) {
296299
return HAL_TIMEOUT;
297300
}
298-
__WFI();
299301
}
300302
return HAL_OK;
301303
}

0 commit comments

Comments
 (0)