GD32移植FATFS文件系统

下载地址

http://elm-chan.org/fsw/ff/00index_e.html

https://download.csdn.net/download/shaynerain/20678221

解压后

文档

在doc中有相关介绍文档,提示我们需要不同这六个函数

在src中有readme文件

里面介绍了每个文件的内容

系统

非常重要的问题,在系统中使用需要考虑线程安全问题,在syscall.c中给出了相关的解决方式

使用系统

必须添加syscall.c

不使用系统

只需要添加ff.c和diskio.c

修改文件

diskio.c

diskio中的文件进行补全

disk_status,可直接返回0

disk_initialize,写入初始化,如果已经初始化过设备可以直接返回0

disk_read,读函数,需要注意,读指的是读一个block,即512个字节,在设备中需要区分

disk_write,写函数,同上

disk_ioct1,命令相关,该函数需要注意,在配置文件中不一样的配置需要不一样的内容,具体可查看http://elm-chan.org/fsw/ff/doc/dioctl.html

get_fattime,该函数可直接返回0,可添加该函数,如果_FS_NORTC=1不必提供

syscall.c

这里使用了FreeRTOS系统,需要进行修改

在ffconf.h中,需要使能_FS_REENTRANT

#define _FS_REENTRANT	0
#define _FS_TIMEOUT		1000
#define	_SYNC_t			HANDLE
/* The _FS_REENTRANT option switches the re-entrancy (thread safe) of the FatFs
/  module itself. Note that regardless of this option, file access to different
/  volume is always re-entrant and volume control functions, f_mount(), f_mkfs()
/  and f_fdisk() function, are always not re-entrant. Only file/directory access
/  to the same volume is under control of this feature.
/
/   0: Disable re-entrancy. _FS_TIMEOUT and _SYNC_t have no effect.
/   1: Enable re-entrancy. Also user provided synchronization handlers,
/      ff_req_grant(), ff_rel_grant(), ff_del_syncobj() and ff_cre_syncobj()
/      function, must be added to the project. Samples are available in
/      option/syscall.c.
/
/  The _FS_TIMEOUT defines timeout period in unit of time tick.
/  The _SYNC_t defines O/S dependent sync object type. e.g. HANDLE, ID, OS_EVENT*,
/  SemaphoreHandle_t and etc.. A header file for O/S definitions needs to be
/  included somewhere in the scope of ff.c. */

 按照提示修改

#define _SYNC_t SemaphoreHandle_t

并且在添加头文件

#include "FreeRTOS.h"

#include "queue.h"

#include "semphr.h"

接下来修改函数部分

按照提示取消FreeTROS屏蔽

  • 1
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值