将FATFS移植STM32RBT6遇到的挂载不成功和返回值问题(2)
0res= f_mount(&fs,(TCHAR*)0,1); /* Mount a logical drive */;的时候老返回FR_INVALID_DRIVE,/* (11) The logical drive number is invalid */挂载失败。如果你也遇到这个问题建议改成res= f_mount(&fs,(TCHAR*)1,1);这种形式就行了,但是打开文件和读文件内容时还要这么写
res=exf_getfree("0:",&nCapacity,&free);//得到SD卡的总容量和剩余容量
res=f_open(&file, "0:/test.txt", FA_OPEN_EXISTING|FA_READ);
res=f_read (
&file, /* Pointer to the file object */
buffer,/* Pointer to data buffer */
512,/* Number of bytes to read */
&br/* Pointer to number of bytes read */
) ;
好了,废话不多说,把main函数应用层代码粘贴出来
FATFS fs;FIL file; //文件1
FIL ftemp; //文件2.
UINT br,bw;//读写变量
FILINFO fileinfo;//文件信息
DIR dir;
FILINFO fileInfo;
UINT br,bw;
FRESULT res;
u32 nCapacity;
char buffer[512];
int main(void)
{
u32 total,free;
BspInit();
res= SD_Init();
if(res==0)
{
DebugOut(0, "sd卡初始化成功!");
}
res= f_mount(&fs,(TCHAR*)1,1); /* Mount a logical drive */;
//f_mkfs(0,1,4096);
res=exf_getfree("0:",&nCapacity,&free);//得到SD卡的总容量和剩余容量
DebugOut(0,"总容量:%dKB,剩余容量:%dKB",nCapacity,free);
res=f_open(&file, "0:/test.txt", FA_OPEN_EXISTING|FA_READ);
res=f_read (
&file, /* Pointer to the file object */
buffer,/* Pointer to data buffer */
512,/* Number of bytes to read */
&br/* Pointer to number of bytes read */
) ;
DebugOut(0,"buffer:%s",buffer);
res= f_mount(NULL,(TCHAR*)1,1);
while(1);
}
FATFS移植STM32RBT6挂载不成功返回 相关文章:
- Windows CE 进程、线程和内存管理(11-09)
- RedHatLinux新手入门教程(5)(11-12)
- uClinux介绍(11-09)
- openwebmailV1.60安装教学(11-12)
- Linux嵌入式系统开发平台选型探讨(11-09)
- Windows CE 进程、线程和内存管理(二)(11-09)