將FATFS移植STM32RBT6遇到的掛載不成功和返回值問題
移植前做了大量準(zhǔn)備,在網(wǎng)上尤其是原子論壇翻看各種其他人移植的心得,去fatfs的官方網(wǎng)站下載0.10版本的程序,看各種相關(guān)的移植心得,文檔版本眾多,眼花繚亂,花了點時間看了看一些函數(shù)??吹貌畈欢嗔耍椭苯影?.10的版本考到自己的工程目錄下開始make,經(jīng)過大量的翻閱和實踐,要動的地方只有diskio.c和ffconfig.h,第一個需要把底層驅(qū)動函數(shù)sd_inti();添加進去。sd卡的讀單塊和讀多塊,寫單塊寫多塊填進去,ffconfig.h里邊需要改幾個宏定義的值參照別人的例程就可以實現(xiàn)很簡單。
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的返回值轉(zhuǎn)成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);
}
// 返回值轉(zhuǎn)換
if(res == 0)
{
return RES_OK;
}
else
{
return RES_ERROR;
}
}
#endif /* _READONLY */
評論