金牌会员
 
- 积分
- 1115
- 金钱
- 1115
- 注册时间
- 2016-8-1
- 在线时间
- 235 小时
|
1金钱
本帖最后由 rindy 于 2018-4-25 13:20 编辑
原子例程中的函数原型
//打开路径下的文件
//path:路径+文件名
//mode:打开模式
//返回值:执行结果
u8 mf_open(u8*path,u8 mode)
{
u8 res;
res=f_open(file,(const TCHAR*)path,mode);//打开文件夹
return res;
}
我调用这个函数打开我SD卡中文件的时候偶尔打开成功即返回值是0x00,但是有时候返回值确是0x09即失败后来查到0x09代表The file/directory object is invalid 即说明打开的文件是无效的,但是为什么相同一个文件有时候能打开有时候又说此文件是无效的呢?
typedef enum {
FR_OK = 0, /* (0) Succeeded */
FR_DISK_ERR, /* (1) A hard error occurred in the low level disk I/O layer */
FR_INT_ERR, /* (2) Assertion failed */
FR_NOT_READY, /* (3) The physical drive cannot work */
FR_NO_FILE, /* (4) Could not find the file */
FR_NO_PATH, /* (5) Could not find the path */
FR_INVALID_NAME, /* (6) The path name format is invalid */
FR_DENIED, /* (7) Access denied due to prohibited access or directory full */
FR_EXIST, /* (8) Access denied due to prohibited access */
FR_INVALID_OBJECT, /* (9) The file/directory object is invalid */
FR_WRITE_PROTECTED, /* (10) The physical drive is write protected */
FR_INVALID_DRIVE, /* (11) The logical drive number is invalid */
FR_NOT_ENABLED, /* (12) The volume has no work area */
FR_NO_FILESYSTEM, /* (13) There is no valid FAT volume */
FR_MKFS_ABORTED, /* (14) The f_mkfs() aborted due to any parameter error */
FR_TIMEOUT, /* (15) Could not get a grant to access the volume within defined period */
FR_LOCKED, /* (16) The operation is rejected according to the file sharing policy */
FR_NOT_ENOUGH_CORE, /* (17) LFN working buffer could not be allocated */
FR_TOO_MANY_OPEN_FILES, /* (18) Number of open files > _FS_SHARE */
FR_INVALID_PARAMETER /* (19) Given parameter is invalid */
} FRESULT;
|
最佳答案
查看完整内容[请看2#楼]
解决了,是我自己的错,把一个为fatfs申请内存的函数放到了打开文件函数前面了,导致每次打开一个文件重新申请了内存而出错了,把这个函数放到main函数前就可以了,申请一次就行了
|