[{"createTime":1735734952000,"id":1,"img":"hwy_ms_500_252.jpeg","link":"https://activity.huaweicloud.com/cps.html?fromacct=261f35b6-af54-4511-a2ca-910fa15905d1&utm_source=V1g3MDY4NTY=&utm_medium=cps&utm_campaign=201905","name":"华为云秒杀","status":9,"txt":"华为云38元秒杀","type":1,"updateTime":1735747411000,"userId":3},{"createTime":1736173885000,"id":2,"img":"txy_480_300.png","link":"https://cloud.tencent.com/act/cps/redirect?redirect=1077&cps_key=edb15096bfff75effaaa8c8bb66138bd&from=console","name":"腾讯云秒杀","status":9,"txt":"腾讯云限量秒杀","type":1,"updateTime":1736173885000,"userId":3},{"createTime":1736177492000,"id":3,"img":"aly_251_140.png","link":"https://www.aliyun.com/minisite/goods?userCode=pwp8kmv3","memo":"","name":"阿里云","status":9,"txt":"阿里云2折起","type":1,"updateTime":1736177492000,"userId":3},{"createTime":1735660800000,"id":4,"img":"vultr_560_300.png","link":"https://www.vultr.com/?ref=9603742-8H","name":"Vultr","status":9,"txt":"Vultr送$100","type":1,"updateTime":1735660800000,"userId":3},{"createTime":1735660800000,"id":5,"img":"jdy_663_320.jpg","link":"https://3.cn/2ay1-e5t","name":"京东云","status":9,"txt":"京东云特惠专区","type":1,"updateTime":1735660800000,"userId":3},{"createTime":1735660800000,"id":6,"img":"new_ads.png","link":"https://www.iodraw.com/ads","name":"发布广告","status":9,"txt":"发布广告","type":1,"updateTime":1735660800000,"userId":3},{"createTime":1735660800000,"id":7,"img":"yun_910_50.png","link":"https://activity.huaweicloud.com/discount_area_v5/index.html?fromacct=261f35b6-af54-4511-a2ca-910fa15905d1&utm_source=aXhpYW95YW5nOA===&utm_medium=cps&utm_campaign=201905","name":"底部","status":9,"txt":"高性能云服务器2折起","type":2,"updateTime":1735660800000,"userId":3}]
(一)下载FATFS源码
说明:共有8个文件diskio.c和diskio.h是硬件层,ff.c和ff.h是FatFs的文件系统层和文件系统的API层,integer.h是文件系统所用到的数据类型的定义,tff.c和tff.h是Tiny的文件系统层和文件系统的API层
(二)修改FATFS
主要修改底层设备驱动函数:diskio.c
目的:就是把 diskio.c 中的函数接口与SPI Flash
芯片驱动连接起来。总共有五个函数,分别为设备状态获取(disk_status)、设备初始化(disk_initialize)、扇区读取(disk_read)、扇区写入(disk_write)、其他控制(disk_ioctl)。
还有修改ffconf.h
目的:根据需求来配置ffconf.h里面的宏定义
(三)挂在文件系统
1.创建一些对象
FATFS fs; /* FatFs文件系统对象 /
FIL fnew; / 文件对象 /
FRESULT res_flash; / 文件操作结果 /
UINT fnum; / 文件成功读写数量 */
2.文件系统的挂在
//在外部SPI Flash挂载文件系统,文件系统挂载时会对SPI设备初始化
res_flash = f_mount(&fs,“1:”,1);
如果没有文件系统就格式化创建文件系统
/* 如果没有文件系统就格式化创建创建文件系统 /
if(res_flash == FR_NO_FILESYSTEM)
{
/ 格式化 */
res_flash=f_mkfs(“1:”,0,0);
if(res_flash == FR_OK) { /* 格式化后,先取消挂载 */ res_flash = f_mount(NULL,"1:",1);
/* 重新挂载 */ res_flash = f_mount(&fs,"1:",1); }
}
(四)文件系统:写入
1.先打开文件
res_flash = f_open(&fnew, “1:FatFs读写测试文件.txt”,FA_CREATE_ALWAYS | FA_WRITE );
//不存在就创建一个
2.将存储区的内容写入文件内
res_flash=f_write(&fnew,WriteBuffer,sizeof(WriteBuffer),&fnum);
3.关闭文件
f_close(&fnew);
(五)文件系统:读出
1.打开文件
res_flash = f_open(&fnew, “1:FatFs读写测试文件.txt”, FA_OPEN_EXISTING | FA_READ);
2.将文件内容读取到缓冲区
res_flash = f_read(&fnew, ReadBuffer, sizeof(ReadBuffer), &fnum);
3.关闭文件
f_close(&fnew);