The FatFs module is assuming following terms on portability.
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.
AVR | H8/300H | MSP430 | TLCS-870/C | V850ES | SH2 | |
---|---|---|---|---|---|---|
Compiler | gcc | CH38 | CL430 | CC870C | CA850 | SHC |
_MCU_ENDIAN | 1 | 2 | 2 | 1 | 1 | 2 |
FatFs Code (Standard, R/W cfg.) | 8722 | 8776 | 6402 | 7338 | ||
FatFs Code (Minimum, R/W cfg.) | 5814 | 5722 | 4094 | 4906 | ||
FatFs Code (Standard, R/O cfg.) | 4248 | 4096 | 3010 | 3506 | ||
FatFs Code (Minimum, R/O cfg.) | 3038 | 3110 | 2210 | 2698 | ||
FatFs Work (Static) | D*2 + 2 | D*4 + 2 | D*4 + 2 | D*4 + 2 | ||
FatFs Work (Dynamic) | D*554 + F*544 | D*554 + F*550 | D*554 + F*550 | D*554 + F*550 | ||
Tiny-FatFs Code (Standard, R/W cfg.) | 7264 | 7240 | 6634 | 8837 | ||
Tiny-FatFs Code (Minimum, R/W cfg.) | 4750 | 4806 | 4366 | 6163 | ||
Tiny-FatFs Code (Standard, R/O cfg.) | 3600 | 3548 | 3212 | 4347 | ||
Tiny-FatFs Code (Minimum, R/O cfg.) | 2568 | 2702 | 2394 | 3322 | ||
Tiny-FatFs Wrok (Static) | 4 | 6 | 4 | 4 | ||
Tiny-FatFs Work (Dynamic) | 544 + F*28 | 544 + F*32 | 544 + F*28 | 544 + F*28 |
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.
Memory Size | FAT 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.
For good performance on reading/writing files on the small embedded system, application program should consider what process is done in the FatFs module. The file data on the disk is transferred by f_read function in following process.
Figure 1. Sector miss-aligned read (short)
Figure 2. Sector miss-aligned read (long)
Figure 3. Sector aligned 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 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.
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.
An interruption in the red section can cause a cross link; as a result, the file/directory being changed will be lost. There is one or more possibility listed below when an interruption in the yellow section is occured.
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.
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.