通过FATFS同时对多个文件写数据的问题

2019-12-21 12:12发布

我通过RT-Thread开了两个优先级相同的线程。在两个线程中分别用FATFS向U盘中写数据,也是写成两个不同的文件用的独立的文件句柄。数据是从DMA传来的,但是写数据的过程中发现f_write返回的是FR_INT_ERR错误。两个线程如果只开其中一个写数据是正常的,FATFS不能同时向多个文件写数据么。请问出现问题的原因在哪?谢谢。
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
该问题目前已经被作者或者管理员关闭, 无法添加新回复
3条回答
not_at_all
1楼-- · 2019-12-21 21:11
配置文件有相关设置,下面的设了没有(ff13a )
  
第一项是重复打开操作同一个文件
第二项是FATFS的可重入

#define FF_FS_LOCK                0
/* The option FF_FS_LOCK switches file lock function to control duplicated file open
/  and illegal operation to open objects. This option must be 0 when FF_FS_READONLY
/  is 1.
/
/  0:  Disable file lock function. To avoid volume corruption, application program
/      should avoid illegal open, remove and rename to the open objects.
/  >0: Enable file lock function. The value defines how many files/sub-directories
/      can be opened simultaneously under file lock control. Note that the file
/      lock control is independent of re-entrancy. */


#define FF_FS_REENTRANT        0
#define FF_FS_TIMEOUT        1000
#define FF_SYNC_t                HANDLE
/* The option FF_FS_REENTRANT 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 function.
/
/   0: Disable re-entrancy. FF_FS_TIMEOUT and FF_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 FF_FS_TIMEOUT defines timeout period in unit of time tick.
/  The FF_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.h. */
xckhmf
2楼-- · 2019-12-21 16:20
要设置下FATFS的可重入
aozima
3楼-- · 2019-12-22 00:06
本帖最后由 aozima 于 2018-2-23 09:34 编辑
  1. /* Reentrancy (thread safe) of the FatFs module.  */
  2. #define RT_DFS_ELM_REENTRANT
复制代码

RT-Thread里面,设置上面的参数,会自动把 FF_FS_REENTRANT  设置为1

另外DMA要特别留意一下buf地址对齐
有些DMA自己支持非对齐拆分(如F4),需要设置为字节传输。
不支持的,如F1,需要自己做判断,有必要的话,本地做一次拷贝。

有cache的硬件上面,还需要做cache line对齐,并手动刷新cache

一周热门 更多>