野火电子论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 9874|回复: 2

FATFS文件系统的SD卡移植

[复制链接]
发表于 2019-3-12 11:37:28 | 显示全部楼层 |阅读模式
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;
        }
}



回复

使用道具 举报

发表于 2019-3-12 14:10:27 | 显示全部楼层
因为sd卡会自己完成擦除,不需要额外的命令
回复 支持 反对

使用道具 举报

 楼主| 发表于 2019-3-12 14:31:06 | 显示全部楼层
flyleaf 发表于 2019-3-12 14:10
因为sd卡会自己完成擦除,不需要额外的命令

嗯,多谢蛤
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

联系站长|手机版|野火电子官网|野火淘宝店铺|野火电子论坛 ( 粤ICP备14069197号 ) 大学生ARM嵌入式2群

GMT+8, 2024-4-18 13:49 , Processed in 0.041797 second(s), 23 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表