初中生
最后登录1970-1-1
在线时间 小时
注册时间2024-4-12
|
本帖最后由 wbb_forever 于 2024-4-12 21:46 编辑
格式化文件系统后只能写入一次文件,再次写入文件时无法写入,显示剩余空间为空,并且flash里面内容也会被清空,使用野火的例程也会出现这个情况,是什么原因呢?main函数代码如下:
static void malloc_size()
{
FATFS *pfs;
DWORD fre_clust, fre_sect, tot_sect;
res2 = f_getfree("1:", &fre_clust, &pfs);
tot_sect = (pfs->n_fatent - 2) * pfs->csize;
fre_sect = fre_clust * pfs->csize;
printf("》设备总空间:%10lu KB。\n》可用空间: %10lu KB。\n", tot_sect *4, fre_sect *4);
}
int main(void)
{
USART_Config();
res = f_mount(&FsObject,"1:",1);//调用spi初始化函数
//
// res = f_mkfs("1:",0,0);
// res = f_mount(&FsObject,"1:",1);
printf("f_mount_res = %d\n",res);
if(res == FR_NO_FILESYSTEM)
{
printf("进入格式化!\n");
res = f_mkfs("1:",0,0);
printf("f_mkfs_res = %d\n",res);
//格式化后要取消挂载再重新挂载文件系统
res = f_mount(NULL,"1:",1);
res = f_mount(&FsObject,"1:",1);
printf("f_mkfs_res2 = %d\n",res);
}
malloc_size();
res = f_open(&fp,"1:1bbbbbbbbbbbbbbba.txt",FA_OPEN_ALWAYS|FA_WRITE|FA_READ);
if(res == FR_OK)
{
res = f_write(&fp,write_buff,sizeof(write_buff),&w_p_num);
printf("w_p_num = %d\n",w_p_num);
f_lseek(&fp,0);
if(res == FR_OK)
{
res = f_read(&fp,read_buff,f_size(&fp),&r_p_num);
printf("r_p_num = %d\n",r_p_num);
if(res == FR_OK)
{
printf("读出内容 : %s\n",read_buff);
}
}
f_close(&fp);
}
malloc_size();
f_mount(NULL,"1:",1);
printf("文件关闭!\n");
while(1)
{};
}
|
|