开心 已解决 我自己来解答吧 看了看论坛上其他的帖子,发现问题好像是说U盘没有格式化或者U盘的FATFS和程序的不兼容怎么样的
具体问题原因参考ff.h头文件下的如下一段代码中的 FR_NO_FILESYSTEM, /* (13) There is no valid FAT volume */一行
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;
具体问题原因参考ff.h头文件下的如下一段代码中的 FR_NO_FILESYSTEM, /* (13) There is no valid FAT volume */一行
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;
我的解决办法是在//用户测试主程序u8 USH_User_App(void)函数中初始化了一次U盘,之后连接就正常了 就不需要初始化了 就注释掉了
贴出代码如下
u8 USH_User_App(void)
{
u32 total,free;
u8 res=0;
printf("设备连接成功!. ");
// res=f_mkfs("2:",1,0);
// if(res==0)
// {
// f_setlabel((const TCHAR *)"2:ALIENTEK"); //设置Flash磁盘的名字为:ALIENTEK
// printf("Disk Format Finish "); //格式化完成
// }else printf("Disk Format Error "); //格式化失败
// delay_ms(1000);
res=exf_getfree("2:",&total,&free);
if(res==0)
{
printf("FATFS OK!");
printf("U Disk Total Size:%d MB",total);
printf("U Disk Free Size: %d MB",free);
}
while(HCD_IsDeviceConnected(&USB_OTG_Core))//设备连接成功
{
LED1=!LED1;
delay_ms(200);
}
return res;
}
一周热门 更多>