FATFS文件系统的底层接口,disk_write中添加SD卡扇区写操作时为什么没有像spi flash移植FATFS那样先进行擦除操作???
spi flash的disk_write
DRESULT TM_FATFS_FLASH_SPI_disk_write(BYTE *buff, DWORD sector, UINT count)
{
uint32_t write_addr;
FLASH_DEBUG_FUNC();
sector+=512;
write_addr = sector<<12;
SPI_FLASH_SectorErase(write_addr);//进行擦除
SPI_FLASH_BufferWrite(buff,write_addr,4096);
return RES_OK;
}
SD的disk_write
DRESULT TM_FATFS_SD_SDIO_disk_write(BYTE *buff, DWORD sector, UINT count)
{
SD_Error Status = SD_OK;
if (!TM_FATFS_SDIO_WriteEnabled()) {
return RES_WRPRT;
}
if (SD_Detect() != SD_PRESENT) {
return RES_NOTRDY;
}
if ((DWORD)buff & 3) {
DRESULT res = RES_OK;
DWORD scratch[BLOCK_SIZE / 4];
while (count--) {
memcpy(scratch, buff, BLOCK_SIZE);
res = TM_FATFS_SD_SDIO_disk_write((void *)scratch, sector++, 1);
if (res != RES_OK) {
break;
}
buff += BLOCK_SIZE;
}
return(res);
}
Status = SD_WriteMultiBlocks((uint8_t *)buff, (uint64_t)sector << 9, BLOCK_SIZE, count); // 4GB Compliant
if (Status == SD_OK) {
SDTransferState State;
Status = SD_WaitWriteOperation(); // Check if the Transfer is finished
while ((State = SD_GetStatus()) == SD_TRANSFER_BUSY); // BUSY, OK (DONE), ERROR (FAIL)
if ((State == SD_TRANSFER_ERROR) || (Status != SD_OK)) {
return RES_ERROR;
} else {
return RES_OK;
}
} else {
return RES_ERROR;
}
} |