//Task 20
void Task20_DataAccesss(void *pdata)
{
pdata = pdata;
INT8U err;
u8 data1[512] = { "12345678" };
u8 data2[512] = { "0" };
FATFS fs;
FIL file;
FRESULT res;
UINT btw, bw;
OSTimeDlyHMSM(0, 0, 10, 0 ); /* Wait 10 second */
//开打文件 test1.txt , 如果该文件不存在, 创建该文件:
res = f_mount(0, &fs);
if(res == FR_OK)
{
res = f_open(&file, "test1.txt", FA_OPEN_ALWAYS | FA_READ | FA_WRITE);
if(res == FR_OK)/* 这一处进不来, 检查res值为13,即FR_NO_FILESYSTEM, (13) There is no valid FAT volume on the physical drive */
{
btw = 256, bw = 0;
res = f_write(&file, data1, btw, &bw);
if(res == FR_OK) {
if(btw == bw)
{}
}
//f_close(&file);
}
//else f_mount(0, NULL);
}
//读取文件 test1.txt 前8个字节:
btw = 8, bw = 0;
res = f_read(&file, data2, btw, &bw);
if(res == FR_OK)
{
if(btw == bw)
{
//显示接收数据:
LCMprintf( 0, 80, "%3d", data2[0]);
LCMprintf( 3, 80, "%3d", data2[1]);
LCMprintf( 6, 80, "%3d", data2[2]);
LCMprintf( 9, 80, "%3d", data2[3]);
LCMprintf(12, 80, "%3d", data2[4]);
LCMprintf(15, 80, "%3d", data2[5]);
LCMprintf(18, 80, "%3d", data2[6]);
LCMprintf(21, 80, "%3d", data2[7]);
}
}
f_close(&file);
f_mount(0, NULL);
while(1)
{
OSSemPend (AckSem, 0, &err);
}
}
为什么res = f_open(&file, "test1.txt", FA_OPEN_ALWAYS | FA_READ | FA_WRITE);的返回结果值为13:
FR_NO_FILESYSTEM, (13) There is no valid FAT volume on the physical drive */