diff --git a/bootloader/libs/fatfs/diskio.c b/bootloader/libs/fatfs/diskio.c index 73a21e7..c35d39f 100644 --- a/bootloader/libs/fatfs/diskio.c +++ b/bootloader/libs/fatfs/diskio.c @@ -46,7 +46,8 @@ DRESULT disk_read ( UINT count /* Number of sectors to read */ ) { - if ((u32)buff >= DRAM_START) + // Ensure that buffer resides in DRAM and it's DMA aligned. + if (((u32)buff >= DRAM_START) && !((u32)buff % 8)) return sdmmc_storage_read(&sd_storage, sector, count, buff) ? RES_OK : RES_ERROR; u8 *buf = (u8 *)SDMMC_UPPER_BUFFER; if (sdmmc_storage_read(&sd_storage, sector, count, buf)) @@ -67,9 +68,10 @@ DRESULT disk_write ( UINT count /* Number of sectors to write */ ) { - if ((u32)buff >= DRAM_START) + // Ensure that buffer resides in DRAM and it's DMA aligned. + if (((u32)buff >= DRAM_START) && !((u32)buff % 8)) return sdmmc_storage_write(&sd_storage, sector, count, (void *)buff) ? RES_OK : RES_ERROR; - u8 *buf = (u8 *)SDMMC_UPPER_BUFFER; //TODO: define this somewhere. + u8 *buf = (u8 *)SDMMC_UPPER_BUFFER; memcpy(buf, buff, 512 * count); if (sdmmc_storage_write(&sd_storage, sector, count, buf)) return RES_OK; diff --git a/nyx/nyx_gui/libs/fatfs/diskio.c b/nyx/nyx_gui/libs/fatfs/diskio.c index 73a21e7..c35d39f 100644 --- a/nyx/nyx_gui/libs/fatfs/diskio.c +++ b/nyx/nyx_gui/libs/fatfs/diskio.c @@ -46,7 +46,8 @@ DRESULT disk_read ( UINT count /* Number of sectors to read */ ) { - if ((u32)buff >= DRAM_START) + // Ensure that buffer resides in DRAM and it's DMA aligned. + if (((u32)buff >= DRAM_START) && !((u32)buff % 8)) return sdmmc_storage_read(&sd_storage, sector, count, buff) ? RES_OK : RES_ERROR; u8 *buf = (u8 *)SDMMC_UPPER_BUFFER; if (sdmmc_storage_read(&sd_storage, sector, count, buf)) @@ -67,9 +68,10 @@ DRESULT disk_write ( UINT count /* Number of sectors to write */ ) { - if ((u32)buff >= DRAM_START) + // Ensure that buffer resides in DRAM and it's DMA aligned. + if (((u32)buff >= DRAM_START) && !((u32)buff % 8)) return sdmmc_storage_write(&sd_storage, sector, count, (void *)buff) ? RES_OK : RES_ERROR; - u8 *buf = (u8 *)SDMMC_UPPER_BUFFER; //TODO: define this somewhere. + u8 *buf = (u8 *)SDMMC_UPPER_BUFFER; memcpy(buf, buff, 512 * count); if (sdmmc_storage_write(&sd_storage, sector, count, buf)) return RES_OK;