aboutsummaryrefslogtreecommitdiffstats
path: root/os
diff options
context:
space:
mode:
authorJosé Simões <jose.simoes@eclo.solutions>2019-03-10 11:33:40 +0000
committerGitHub <noreply@github.com>2019-03-10 11:33:40 +0000
commita3e31145803753b70239f60db6b73597d3a06511 (patch)
tree6db5855df0079bd4978a0f820568e2e033e8853c /os
parent4dfaea2dece78ea1796b9d666ce1a373ccba200b (diff)
downloadChibiOS-Contrib-a3e31145803753b70239f60db6b73597d3a06511.tar.gz
ChibiOS-Contrib-a3e31145803753b70239f60db6b73597d3a06511.tar.bz2
ChibiOS-Contrib-a3e31145803753b70239f60db6b73597d3a06511.zip
Fix F7 cache invalidation on write operation
Diffstat (limited to 'os')
-rw-r--r--os/various/fatfs_bindings/fatfs_diskio.c23
1 files changed, 17 insertions, 6 deletions
diff --git a/os/various/fatfs_bindings/fatfs_diskio.c b/os/various/fatfs_bindings/fatfs_diskio.c
index 39a8658..7f510a0 100644
--- a/os/various/fatfs_bindings/fatfs_diskio.c
+++ b/os/various/fatfs_bindings/fatfs_diskio.c
@@ -206,8 +206,6 @@ DRESULT disk_write (
UINT count /* Number of sectors to write (1..255) */
)
{
- // invalidate cache on buffer
- cacheBufferFlush(buff, count * MMCSD_BLOCK_SIZE);
switch (pdrv) {
#if HAL_USE_MMC_SPI
@@ -218,11 +216,15 @@ DRESULT disk_write (
return RES_WRPRT;
if (mmcStartSequentialWrite(&FATFS_HAL_DEVICE, sector))
return RES_ERROR;
+
while (count > 0) {
- if (mmcSequentialWrite(&FATFS_HAL_DEVICE, buff))
- return RES_ERROR;
- buff += MMCSD_BLOCK_SIZE;
- count--;
+ // invalidate cache on buffer
+ cacheBufferFlush(buff, MMCSD_BLOCK_SIZE);
+
+ if (mmcSequentialWrite(&FATFS_HAL_DEVICE, buff))
+ return RES_ERROR;
+ buff += MMCSD_BLOCK_SIZE;
+ count--;
}
if (mmcStopSequentialWrite(&FATFS_HAL_DEVICE))
return RES_ERROR;
@@ -231,8 +233,13 @@ DRESULT disk_write (
case SDC:
if (blkGetDriverState(&FATFS_HAL_DEVICE) != BLK_READY)
return RES_NOTRDY;
+
+ // invalidate cache on buffer
+ cacheBufferFlush(buff, count * MMCSD_BLOCK_SIZE);
+
if (sdcWrite(&FATFS_HAL_DEVICE, sector, buff, count))
return RES_ERROR;
+
return RES_OK;
#endif
#if HAL_USBH_USE_MSD
@@ -240,6 +247,10 @@ DRESULT disk_write (
/* It is initialized externally, just reads the status.*/
if (blkGetDriverState(&MSBLKD[0]) != BLK_READY)
return RES_NOTRDY;
+
+ // invalidate cache on buffer
+ cacheBufferFlush(buff, count * MSBLKD[0].info.blk_size);
+
if (usbhmsdLUNWrite(&MSBLKD[0], sector, buff, count))
return RES_ERROR;
return RES_OK;