Skip to content

Commit 799356e

Browse files
committed
sdcard: Use dma_protect_rx_region on read operations.
Will avoid corruption for unaligned reads, unless a SPI DMA operation is in progress at the same time (to be fixed separately). This fixes the unit test added in the parent commit. This work was funded through GitHub Sponsors. Signed-off-by: Angus Gratton <angus@redyak.com.au>
1 parent b2998e2 commit 799356e

1 file changed

Lines changed: 3 additions & 1 deletion

File tree

ports/stm32/sdcard.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -574,7 +574,7 @@ mp_uint_t sdcard_read_blocks(uint8_t *dest, uint32_t block_num, uint32_t num_blo
574574

575575
// make sure cache is flushed and invalidated so when DMA updates the RAM
576576
// from reading the peripheral the CPU then reads the new data
577-
MP_HAL_CLEANINVALIDATE_DCACHE(dest, num_blocks * SDCARD_BLOCK_SIZE);
577+
dma_protect_rx_region(dest, num_blocks * SDCARD_BLOCK_SIZE);
578578

579579
sdcard_reset_periph();
580580
#if MICROPY_HW_ENABLE_MMCARD
@@ -589,6 +589,8 @@ mp_uint_t sdcard_read_blocks(uint8_t *dest, uint32_t block_num, uint32_t num_blo
589589
err = sdcard_wait_finished();
590590
}
591591

592+
dma_unprotect_rx_region(dest, num_blocks * SDCARD_BLOCK_SIZE);
593+
592594
#if SDIO_USE_GPDMA
593595
dma_deinit(&SDMMC_DMA);
594596
#if MICROPY_HW_ENABLE_MMCARD

0 commit comments

Comments
 (0)