1 平台
mcu nordic 52840 ,flash Macronix MX25
2 版本
ff14
3 过程
1)添加文件
diskio.c diskio.h ff.c ff.h ffconf.h ffunicode.c (ffsystem.c 系统相关,不添加)
2)修改内容
/*****diskio.c*******/ //主要修改初始化接口以及读写接口
定义spiflash
#define DEV_SPIFLASH 0
DSTATUS disk_initialize (
BYTE pdrv /* Physical drive nmuber to identify the drive */
)
{
if(pdrv == DEV_SPIFLASH){
app_spiFlashInit();
return RES_OK;
}
return RES_PARERR;
}
DRESULT disk_read (
BYTE pdrv, /* Physical drive nmuber to identify the drive */
BYTE *buff, /* Data buffer to store read data */
LBA_t sector, /* Start sector in LBA */
UINT count /* Number of sectors to read */
)
{
if(pdrv == DEV_SPIFLASH){
app_spiflash_read(( uint8_t *)buff,count,sector);
return RES_OK;
}
return RES_PARERR;
}
DRESULT disk_write (
BYTE pdrv, /* Physical drive nmuber to identify the drive */
const BYTE *buff, /* Data to be written */
LBA_t sector, /* Start sector in LBA */
UINT count /* Number of sectors to write */
)
{
if(pdrv == DEV_SPIFLASH){
app_spiflash_write((const uint8_t *)buff,count,sector);
return RES_OK;
}
return RES_PARERR;
}
DRESULT disk_ioctl (
BYTE pdrv, /* Physical drive nmuber (0..) */
BYTE cmd, /* Control code */
void *buff /* Buffer to send/receive control data */
)
{
DRESULT res = RES_OK;
int result;
switch (pdrv)
{
case DEV_SPIFLASH :
switch(cmd)
{
case CTRL_SYNC:
res = RES_OK;
break;
case GET_SECTOR_SIZE:
*(WORD*)buff = FLASH_SECTOR_SIZE;
res = RES_OK;
break;
case GET_BLOCK_SIZE:
*(WORD*)buff = FLASH_BLOCK_SIZE;
res = RES_OK;
break;
case GET_SECTOR_COUNT:
*(DWORD*)buff = FLASH_SECTOR_COUNT;
res = RES_OK;
break;
default:
res = RES_PARERR;
break;
}
} return res;
}
/*****ffconfig.h*******/ //修改部分宏定义
#define FF_CODE_PAGE 936// 中文支持
#define FF_USE_MKFS 1 //格式化使能
#define FF_MIN_SS 4096 //
#define FF_MAX_SS 4096 //
3)测试
f_mkfs("0:", &opt, work, sizeof work)
...
f_mount(&fs, "0:", 0)
...
f_write(&fil, "Hello,World!", 12, &bw);
这个过程可以参考
https://blog.csdn.net/qq_21475601/article/details/78032854