Skip to content

Commit

Permalink
pkg/fatfs: make use of mtd_write_sector()
Browse files Browse the repository at this point in the history
  • Loading branch information
benpicco committed Dec 14, 2023
1 parent bfe26c6 commit 31e4592
Showing 1 changed file with 3 additions and 14 deletions.
17 changes: 3 additions & 14 deletions pkg/fatfs/fatfs_diskio/mtd/mtd_diskio.c
Original file line number Diff line number Diff line change
Expand Up @@ -130,24 +130,13 @@ DRESULT disk_read(BYTE pdrv, BYTE *buff, DWORD sector, UINT count)
*/
DRESULT disk_write(BYTE pdrv, const BYTE *buff, DWORD sector, UINT count)
{
mtd_dev_t *mtd = fatfs_mtd_devs[pdrv];
DEBUG("disk_write: %d, %lu, %d\n", pdrv, (long unsigned)sector, count);
if ((pdrv >= FF_VOLUMES) || (fatfs_mtd_devs[pdrv]->driver == NULL)) {
if ((pdrv >= FF_VOLUMES) || (mtd->driver == NULL)) {
return RES_PARERR;
}

/* erase memory before writing to it */
int res = mtd_erase_sector(fatfs_mtd_devs[pdrv], sector, count);

if (res != 0) {
return RES_ERROR; /* erase failed! */
}

uint32_t sector_size = fatfs_mtd_devs[pdrv]->page_size
* fatfs_mtd_devs[pdrv]->pages_per_sector;

res = mtd_write_page_raw(fatfs_mtd_devs[pdrv], buff,
sector, 0, count * sector_size);

int res = mtd_write_sector(mtd, buff, sector, count);
if (res != 0) {
return RES_ERROR;
}
Expand Down

0 comments on commit 31e4592

Please sign in to comment.