高中生
最后登录1970-1-1
在线时间 小时
注册时间2016-3-23
|
最近刚学习FATS,但是将程序下进板中 无法得到程序应有的效果(程序为板子配套的代码,而且sd卡驱动能够正常运行)。
经过检查FATS调用函数的返回值,发现如下
res=f_mount(0,&fs);——————0————FR_OK
res = f_open(&fnew, "0:newfile.txt", FA_CREATE_ALWAYS | FA_WRITE );_______13________FR_NO_FILESYSTEM, /* (13) There is no valid FAT volume */
res = f_read(&fnew, buffer, sizeof(buffer), &br); ________9___________FR_INVALID_OBJECT, /* (9) The file/directory object is invalid */
请问下,该如何解决这个问题啊???小弟,拜谢了
下面的是主函数的代码
FIL fnew; /* file objects */
FATFS fs; /* Work area (file system object) for logical drives */
FRESULT res;
UINT br, bw; /* File R/W count */
BYTE buffer[4096]={0}; /* file copy buffer */
BYTE textFileBuffer[] = "Welcome to use Wildfire iso stm32 Development Board today is a good day";
int main(void)
{
/* USART1 config */
USART1_Config();
printf("\r\n this is a fatfs test demo \r\n");
/* Sdio Interrupt Config */
NVIC_Configuration();
/* Register work area for each volume (Always succeeds regardless of disk status) */
res=f_mount(0,&fs);
printf("1___%d ",res);
// f_mkdir("sub");
// f_mkdir("sub/sub1");
/* function disk_initialize() has been called in f_open */
/* Create new file on the drive 0 */
res = f_open(&fnew, "0:newfile.txt", FA_CREATE_ALWAYS | FA_WRITE );
printf("2___%d ",res);
if ( res == FR_OK )
{
res = f_write(&fnew, textFileBuffer, sizeof(textFileBuffer), &bw);
printf("3__%d ",res);
f_close(&fnew);
}
res = f_open(&fnew, "0:newfile.txt", FA_OPEN_EXISTING | FA_READ);
printf("4__%d ",res);
res = f_read(&fnew, buffer, sizeof(buffer), &br);
printf("5__%d ",res);
printf("\r\n %s ", buffer);
/* Close open files */
f_close(&fnew);
/* Unregister work area prior to discard it */
f_mount(0, NULL);
while(1);
}
|
|