Skip to content

Commit 04bbc16

Browse files
committed
mimxrt/sdcard: Add cache coherency operations for DMA transfers.
Add explicit data cache management to ensure DMA transfers work correctly on systems with data cache enabled (e.g., MIMXRT1170). For reads: Clean and invalidate cache before transfer so DMA can update RAM and CPU reads fresh data. For writes: Clean cache to RAM before transfer so DMA reads correct data. This follows the same pattern as ports/stm32/sdcard.c which uses MP_HAL_CLEANINVALIDATE_DCACHE for reads and MP_HAL_CLEAN_DCACHE for writes. Signed-off-by: Andrew Leech <[email protected]>
1 parent 2f1b12e commit 04bbc16

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

ports/mimxrt/sdcard.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -869,6 +869,10 @@ bool sdcard_read(mimxrt_sdcard_obj_t *card, uint8_t *buffer, uint32_t block_num,
869869
return false;
870870
}
871871

872+
// Ensure cache is flushed and invalidated so when DMA updates RAM
873+
// from the peripheral, the CPU reads the new data.
874+
MP_HAL_CLEANINVALIDATE_DCACHE(buffer, block_count * card->block_len);
875+
872876
usdhc_data_t data = {
873877
.enableAutoCommand12 = true,
874878
.enableAutoCommand23 = false,
@@ -908,6 +912,9 @@ bool sdcard_write(mimxrt_sdcard_obj_t *card, uint8_t *buffer, uint32_t block_num
908912
return false;
909913
}
910914

915+
// Ensure cache is flushed to RAM so DMA can read the correct data.
916+
MP_HAL_CLEAN_DCACHE(buffer, block_count * card->block_len);
917+
911918
usdhc_data_t data = {
912919
.enableAutoCommand12 = true,
913920
.enableAutoCommand23 = false,

0 commit comments

Comments
 (0)