硬汉嵌入式论坛

 找回密码
 立即注册
查看: 1594|回复: 3
收起左侧

[客户分享] 最近在做一个M0+主控的项目,分享一个轻量级文件系统

[复制链接]

8

主题

26

回帖

55

积分

初级会员

积分
55
发表于 2022-3-17 11:39:36 | 显示全部楼层 |阅读模式
Petit FatFs  百度搜索即可diskio  文件我用的是模拟SPI协议,这款IC不支持SDIO.

Petit FatFs 是 fatfs文件系统的轻量级版本,功能有限。但对于RAM 非常有限的单片机来说可以考虑一下。
它支持一下文件操作接口
FRESULT pf_mount (FATFS* fs);                                                                /* Mount/Unmount a logical drive */
FRESULT pf_open (const char* path);                                                        /* Open a file */
FRESULT pf_read (void* buff, UINT btr, UINT* br);                        /* Read data from the open file */
FRESULT pf_write (const void* buff, UINT btw, UINT* bw);        /* Write data to the open file */
FRESULT pf_lseek (DWORD ofs);                                                                /* Move file pointer of the open file */
FRESULT pf_opendir (DIR* dj, const char* path);                                /* Open a directory */
FRESULT pf_readdir (DIR* dj, FILINFO* fno);                                        /* Read a directory item from the open directory */

下面这条是我自己加的
DWORD Get_opened_file_size(void);
注意以下几点:
pffconf.h 文件配置更改
#define        PF_USE_READ                1        /* pf_read() function */
#define        PF_USE_DIR                1        /* pf_opendir() and pf_readdir() function */
#define        PF_USE_LSEEK        1        /* pf_lseek() function */
#define        PF_USE_WRITE        1        /* pf_write() function */
功能裁剪
#define PF_FS_FAT12                0        /* FAT12 */
#define PF_FS_FAT16                0        /* FAT16 */
#define PF_FS_FAT32                1        /* FAT32 */

支持的文件系统

我测试过读文件,TXT可以读取 .bin文件读不了.其他的没试过。
写的话,不可以写空的TXT文本。我这边办法是预先填充足够多无意义字符,然后写做替换的。还好我主要使用读功能。
原因是源码中这句代码:pff.c
  remain = fs->fsize - fs->fptr;
  if (btw > remain) btw = (UINT)remain;                        /* Truncate btw by remaining bytes */

附件是V5 F407主控的DEMO源码

SPI_Petit FatFs.rar

5.83 MB, 下载次数: 45

评分

参与人数 1金币 +100 收起 理由
eric2013 + 100 很给力!

查看全部评分

回复

使用道具 举报

1万

主题

6万

回帖

10万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
106746
QQ
发表于 2022-3-17 12:20:07 | 显示全部楼层
谢谢楼主分享。
回复

使用道具 举报

210

主题

1043

回帖

1683

积分

至尊会员

More we do, more we can do.

积分
1683
发表于 2022-3-17 18:19:31 | 显示全部楼层
原来是FatFs作者写的啊,不过为了小型化,损失了很多功能:
Features
Very Small RAM Consumption (44 Bytes Work Area + Certain Stack).
Very Small Code Size (2K-4K bytes).
FAT12, FAT16 and FAT32.
Single Volume and Single File.
Streaming File Read.
File Write Function with Some Restrictions.
回复

使用道具 举报

73

主题

1193

回帖

1412

积分

至尊会员

积分
1412
发表于 2022-3-18 09:19:59 | 显示全部楼层
谢谢分享
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|小黑屋|Archiver|手机版|硬汉嵌入式论坛

GMT+8, 2024-5-3 21:28 , Processed in 0.164805 second(s), 29 queries .

Powered by Discuz! X3.4 Licensed

Copyright © 2001-2023, Tencent Cloud.

快速回复 返回顶部 返回列表