新闻中心

EEPW首页>嵌入式系统>设计应用> 将FATFS移植STM32RBT6遇到的挂载不成功和返回值问题

将FATFS移植STM32RBT6遇到的挂载不成功和返回值问题

作者: 时间:2016-11-27 来源:网络 收藏
移植fatfs遇到了诸多问题,很是苦恼啊,移植成功思来之不易,特分享一下经验。硬件是STM32F103RBT6内存只有20kB,Flash只有128KB,考虑到内存有限,就不能支持长文件名了,在原子论坛上下载的所以要改动,在此感谢原子论坛给我带来的帮助还有安富莱论坛http://bbs.armfly.com/read.php?tid=3601给我带来的启示。另外硬件还有一个大的相机的SD卡,网上买的模块当然也可以自己焊接一个,采用SPI接口,SPI1和SPI2都行,看图

本文引用地址://m.amcfsurvey.com/article/201611/322305.htm

移植前做了大量准备,在网上尤其是原子论坛翻看各种其他人移植的心得,去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 */


上一页 1 2 下一页

评论


技术专区

关闭