将FATFS移植STM32RBT6遇到的挂载不成功和返回值问题
移植前做了大量准备,在网上尤其是原子论坛翻看各种其他人移植的心得,去fatfs的官方网站下载0.10版本的程序,看各种相关的移植心得,文档版本众多,眼花缭乱,花了点时间看了看一些函数。看得差不多了,就直接把0.10的版本考到自己的工程目录下开始make,经过大量的翻阅和实践,要动的地方只有diskio.c和ffconfig.h,第一个需要把底层驱动函数sd_inti();添加进去。sd卡的读单块和读多块,写单块写多块填进去,ffconfig.h里边需要改几个宏定义的值参照别人的例程就可以实现很简单。
DSTATUS disk_initialize (
BYTE drv/* Physical drive nmuber (0..) */
)
{
u8 state;
state=SD_Init();
if(!state){
return STA_NODISK;
}
return 0;
}
/*-----------------------------------------------------------------------*/
/* Return Disk Status */
DSTATUS disk_status (
BYTE drv/* Physical drive nmuber (0..) */
)
{return 0;
}
/*-----------------------------------------------------------------------*/
/* Read Sector(s) */
DRESULT disk_read (
BYTE drv,/* Physical drive nmuber (0..) */
BYTE *buff,/* Data buffer to store read data */
DWORD sector,/* Sector address (LBA) */
BYTE count/* Number of sectors to read (1..255) */
)
{
u8 res=0;
if(count==1) //1个sector的读操作
{
res = SD_ReadSingleBlock(sector, buff);
//res= SD_ReadDisk(buff,sector,count);
}
else //多个sector的读操作
{
res = SD_ReadMultiBlock(sector, buff, count);
}
//处理返回值,将SPI_SD_driver.c的返回值转成ff.c的返回值
if(res == 0x00)
{
return RES_OK;
}
else
{
return RES_ERROR;
}
}
/*-----------------------------------------------------------------------*/
/* Write Sector(s) */
#if _READONLY == 0
DRESULT disk_write (
BYTE drv,/* Physical drive nmuber (0..) */
const BYTE *buff,/* Data to be written */
DWORD sector,/* Sector address (LBA) */
BYTE count/* Number of sectors to write (1..255) */
)
{
u8 res;
// 读写操作
if(count == 1)
{
res = SD_WriteSingleBlock(sector, buff);;
}
else
{
res = SD_WriteMultiBlock(sector, buff, count);
}
// 返回值转换
if(res == 0)
{
return RES_OK;
}
else
{
return RES_ERROR;
}
}
#endif /* _READONLY */
评论