Professional Documents
Culture Documents
Fatfs 模块应用手册: Fatfs Module Application Note
Fatfs 模块应用手册: Fatfs Module Application Note
FatFs 模块应用手册
Considerations on porting to various platform
移植到各种平台的考虑
FatFs 模块的移植性前提是满足以下条件。
ANSI C
The FatFs module is a middleware that written in ANSI C. There is no
platform dependence, so long as the compiler is in compliance with ANSI C.
However it handles the system portable FAT structures. You must take the
endian into consideration. This setting is defined in ff.h (tff.h). It must be
changed for your platform first or the compiler will abort with an error.
储存器使用信息(R0.06 版本)
These are the memory usage on some target systems. The memory sizes are in unit of
byte, D means number of logical drives and F means number of open files. All
samples are optimezed in code size.
这是在一些目标系中的储存器使用信息。储存器大小的单位是字节,D 的意思
是逻辑盘的数量,F 的意思是打开文件的数量。所有范例都是以代码优化的。
MSP43 TLCS-
AVR H8/300H PIC V850ES
0 870/C
gcc(WinAV CC870
Compiler CH38 gcc(C30) CL430 CA850 SH
R) C
_MCU_ENDIAN 1 2 2 2 1 1 2
FatFs Code (Full,
9280 9348 9387 6728 753
R/W)
FatFs Code (Min,
5814 5798 5913 4094 474
R/W)
FatFs Code (Full,
4402 4236 4371 3054 347
R/O)
FatFs Code (Min,
3066 3158 3213 2172 263
R/O)
FatFs Work
D*2+2 D*4+2 D*2+2 D*4+2 D*4
(Static)
FatFs Work D*554+F*5 D*554+F*5 D*554+F*5 D*554+F*5 D*5
(Dynamic) 44 50 44 50 50
Tiny-FatFs Code
7628 7668 7560 7108 9501 5978 664
(Full, R/W)
Tiny-FatFs Code
4684 4820 4698 4390 6322 3678 423
(Min, R/W)
Tiny-FatFs Code
3634 3600 3618 3382 4554 2722 307
(Full, R/O)
Tiny-FatFs Code
2524 2700 2601 2398 3390 1862 230
(Min, R/O)
Tiny-FatFs Wrok
4 6 4 4 4 6 6
(Static)
Tiny-FatFs Work 544+F* 544+F*
544+F*28 544+F*32 544+F*28 544+F*32 544
(Dynamic) 28 28
FatFs 与 Tiny-FatFs 对比
For most applications, such as portable audio and data logger, Tiny-FatFs is the best
choice. However because the Tiny-FatFs does not support FAT32 in default, there is a
limitation that can handle only tiny storage upto 2GB(4GB in FAT64). The FAT32
support can be added by _USE_FAT32 option with an additional code size. The FatFs
is suitable for fast multiple files access, and for multiple drive system.
对于大多数的应用,例如手持的语音或数据记录设备,Tiny-FatFs 是最佳选择。
然而,因为 Tiny-FatFs 默认不支持 FAT32,所以有只能处理 2GB(4GB in
FAT64)容量。FAT32 的支持可以通过加入_USE_FAT32 选项加入,同时代码占
用量增加。FatFs 适合快速多文件访问,和多磁盘系统。
FAT
Memory Size
Type
<= 64MB FAT12
128MB - 2GB FAT16
>= 4GB FAT32
Rignt table shows the correspondence between memory size and FAT type for SD
memroy card and they are shipped with this format. The data area is justified to the
erase block boundary and the memory card works with the best performance. For that
reason, the memory card should not be reformated with PC. When cluster size or FAT
type is changed, the write performance can be decreased.
性能有效的文件访问
为了满足小型嵌入式系统的读写文件的性能,FatFs 模块中的应用程序会考虑怎
样处理数据。磁盘上的文件数据会被函数 f_read 以下图的方法传送。
The file I/O buffer means a sector buffer to read/write a partial data on the sector. On
the FatFs, member buffer[] in the file object is used. On the Tiny-FatFs, member
win[] in the file system object is used.
Tiny-FatFs processes all file data transfer and access to the FAT/directory with only
one sector buffer, so that FAT sector cached into the buffer is lost and it must
reloaded at every cluster boundary. FatFs has a FAT/directory buffer separated from
file I/O buffer, the frequency of FAT accesses is only 1/341, 1/256 or 1/128 (when
cluster is contiguous) compared to Tiny-FatFs. Thus the Tiny-FatFs is sacrificing its
performance in compensation for very small memory footprint.
Figure 1 shows that partial sector data is transferred via the file I/O buffer. At long
data transfer shown in Figure 2, middle of transfer data that aligned to sector
boundary is transferred into memory directly. Figure 3 shows that entier transfer data
is aligned to the sector boundary. In this case, file I/O buffer is not used. At the
unbuffered transfer, maximum extent of sectors are read with disk_read function at a
time but it never across cluster boundary even if it is contiguous.
Therefore taking effort to sector aligned read/write accesss eliminates memcpy and
the read/write performance will be improved. Besides the effect, cached FAT sector is
not flushed during read/write access on the Tiny-FatFs, so that it can achieve same
performance as FatFs and its small memory footprint simultanesously.
Critical section
临界区
When write operation to the FAT file system is interrupted due to any accidental
failure, such as sudden blackout, incorrect disk removal and unrecoverable data error,
the FAT structure can be destroyed. Following images shows the critical section on
the FatFs module.
当在 FAT 文件系统写操作时,由于一些意外的错误中断,例如突然断电,错误
地移除磁盘和不可恢复的数据错误,FAT 结构都会被破坏。下图展示了 FatFs
模块的临界区域。
在红色区域执行时被打断,会产生交叉连接;结果就是,被改名的文件或者目
录丢失。以下列出在黄色区域执行时被打断时会可能发生的情况。
Each case does not affect the files that not in write operation. To minimize risk of data
loss, the critical section can be minimized like shown in Figure 5 by minimizing the
time that file is opened in write mode and using f_sync function properly.
这些情况对于没有在写操作的文件是没有影响的。为了使数据丢失减到最低,
应该像图 5 那样在文件打开进行写操作期间正确使用 f_sync 函数使临界区减到
最小,从而减少临界区时间。
存在的问题与想法
These are the problems and ideas on current revision of FatFs module. However the
main target of FatFs module is 8 bit microcontrollers. These extensions requires much
resource and the FatFs will unable to be ported to the 8 bit system. This may be the
most serious problem on future plan.
racinglam@gmail.com rax@2009-02-02