一 问题
最近使用到了文件系统的读写,中间遇到了一些问题值得深思。
二 源码解析
创建文件:
FRESULT res; do { sprintf(filename,"/sensor_signal/sensor_%d.bin",file_num++); mprintf("filename is:%s \n\r",filename); res=f_open(&file, filename, FA_CREATE_NEW | FA_WRITE); }while(res!=FR_OK);
写文件:
for (uint i = 0; i < 255; i++) { /* code */ memset(TF_Buffer,i,TF_Buffer_Size); f_write( &file, TF_Buffer , TF_Buffer_Size, &bw); osDelay(20); } f_close(&file);
读文件:
res=f_open(&file, filename, FA_READ); while (1) { /* code */ memset(TF_Buffer,0x00,TF_Buffer——Size); osDelay(200); FRESULT res = f_read( &file, TF_Buffer , TF_Buffer_Size, &bw); if(bw < 1) { mprintf("file read over \n\r"); break; } else { } mprintf("file read len is:%d \n\r",bw); dump8(TF_Buffer,40); osDelay(200); }
三 总结
A.文件执行了
f_close(&file);
才会被存储到sd卡中。
B 读文件只能从sd卡中读,无法从缓存中读取。
作者:虚生 出处:https://www.cnblogs.com/dylancao/ 以音频和传感器算法为核心的智能可穿戴产品解决方案提供商 ,提供可穿戴智能软硬件解决方案的设计,开发和咨询服务。 勾搭热线:邮箱:1173496664@qq.com weixin:18019245820 市场技术对接群:347609188 |
![]() |