大学生
最后登录1970-1-1
在线时间 小时
注册时间2016-7-19
|

楼主 |
发表于 2016-8-27 12:07:01
|
显示全部楼层
你好,例程里已经调用了f_mount(0,&fs);
就在49行:res=f_open(&fnew, "0:newfile.txt", FA_CREATE_ALWAYS | FA_WRITE );的上一行。
整个main函数是这样的:
#include "stm32f10x.h"
#include "bsp_sdio_sdcard.h"
#include "bsp_usart1.h"
#include "ff.h"
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 ÕâÊÇÒ»¸ö fatfs test demo \r\n");
/* Sdio Interrupt Config */
NVIC_Configuration();
/* Register work area for each volume (Always succeeds regardless of disk status) */
f_mount(0,&fs);
// 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("%d\n",res); //Êä³öö¾Ù±äÁ¿resµÄÖµ
if ( res == FR_OK )
{
res = f_write(&fnew, textFileBuffer, sizeof(textFileBuffer), &bw);
printf("\r\n Îļþ´´½¨³É¹¦\r\n");
f_close(&fnew);
}
else if(res == FR_EXIST )
{
printf("\r\n ÎļþÒÑ´æÔÚ¦\r\n");
}
res = f_open(&fnew, "0:newfile.txt", FA_OPEN_EXISTING | FA_READ);
res = f_read(&fnew, buffer, sizeof(buffer), &br);
printf("\r\n %s ", buffer);
/* Close open files */
f_close(&fnew);
/* Unregister work area prior to discard it */
f_mount(0, NULL);
while(1);
}
我只添加了一个printf函数,用来检查 调用f_open();后的返回值res。 |
|