#include "stm32f10x.h"
#include "bsp_sdio_sdcard.h"
#include "usart1.h"
#include "ff.h"
# ifndef _FF_H
#include "diskio.h"
# endif
int main (void)
{
USART1_Configuration();
NVIC_Configuration();
disk_initialize(0);
f_mount(0,&fs); //挂在到盘区
res =f_mkdir("newdir"); // 新建文件夹,名为newdir
//FRESULT f_mkdir (const TCHAR*);
res = f_open(&fnew, "0:newfile.txt", FA_CREATE_ALWAYS | FA_WRITE );
if ( res == FR_OK )
{
res = f_write(&fnew, textFileBuffer, sizeof(textFileBuffer), &bw);
f_close(&fnew);
}
else if ( res == FR_EXIST )
{
printf ("\r\n文件已经存在\n");
}
res = f_open(&fnew, "0:newfile.txt", FA_OPEN_EXISTING | FA_READ);
br=1; ///?
for (;;)
{
for (a=0;a<512;a++)
{
buffer[a]=0;
}
res = f_read(&fnew, buffer, sizeof(buffer), &br);
printf(&quot;\r\n %s &quot;, buffer);
if (res||br==0)
{break;}
}
f_close(&fnew); /* Close open files */
/* Unregister work area prior to discard it */
f_mount(0, NULL); //卸载挂载盘区
while(1);
}
编译后 output显示:
Build target 'Target 1'
compiling main.c...
linking...
..\Output\STM-DEMO.axf: Error: L6218E: Undefined symbol f_mkdir (referred from main.o).
..\Output\STM-DEMO.axf: Not enough information to list image symbols.
..\Output\STM-DEMO.axf: Finished: 1 information, 0 warning and 1 error messages.
Target not created
问题:
添加f_mkdir后编译失败,去掉则可。output显示main中没有定义f_mkdir,但我在头文件已经#include “ff.h”,同样是ff.h中的 f_read和f_write 却可以编译通过。。
请教前辈,多谢!
另外,此main函数中 br=1,有什么作用?因为f_read()中有一行 :*br = 0; /* Initialize byte counter */,将br初始化为0,为何在f_read前 还给br赋值1? 此处优点不解。。。
[/td][/tr][/table] |