Skip to content

Commit ff927cb

Browse files
committed
stmhal/spi: Clean and/or invalidate D-cache before SPI DMA transfers.
On MCUs with a cache (eg F7) this must be done or else the SPI data that is transferred is incorrect.
1 parent 9a1b3da commit ff927cb

1 file changed

Lines changed: 4 additions & 1 deletion

File tree

stmhal/spi.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -419,6 +419,7 @@ STATIC void spi_transfer(const pyb_spi_obj_t *self, size_t len, const uint8_t *s
419419
dma_init(&tx_dma, self->tx_dma_descr, self->spi);
420420
self->spi->hdmatx = &tx_dma;
421421
self->spi->hdmarx = NULL;
422+
MP_HAL_CLEAN_DCACHE(src, len);
422423
status = HAL_SPI_Transmit_DMA(self->spi, (uint8_t*)src, len);
423424
if (status == HAL_OK) {
424425
status = spi_wait_dma_finished(self->spi, timeout);
@@ -440,7 +441,7 @@ STATIC void spi_transfer(const pyb_spi_obj_t *self, size_t len, const uint8_t *s
440441
}
441442
dma_init(&rx_dma, self->rx_dma_descr, self->spi);
442443
self->spi->hdmarx = &rx_dma;
443-
444+
MP_HAL_CLEANINVALIDATE_DCACHE(dest, len);
444445
status = HAL_SPI_Receive_DMA(self->spi, dest, len);
445446
if (status == HAL_OK) {
446447
status = spi_wait_dma_finished(self->spi, timeout);
@@ -460,6 +461,8 @@ STATIC void spi_transfer(const pyb_spi_obj_t *self, size_t len, const uint8_t *s
460461
self->spi->hdmatx = &tx_dma;
461462
dma_init(&rx_dma, self->rx_dma_descr, self->spi);
462463
self->spi->hdmarx = &rx_dma;
464+
MP_HAL_CLEAN_DCACHE(src, len);
465+
MP_HAL_CLEANINVALIDATE_DCACHE(dest, len);
463466
status = HAL_SPI_TransmitReceive_DMA(self->spi, (uint8_t*)src, dest, len);
464467
if (status == HAL_OK) {
465468
status = spi_wait_dma_finished(self->spi, timeout);

0 commit comments

Comments
 (0)