最近试玩了STM32用SPI方式操作SD卡,这样就涉及到文件系统,搜索到几种支持FAT16/32的文件,综合考虑,最后选择了完全开源、免费的FATFS,版本是R0.07e,该版本支持长文件名:
Since the FatFs module is completely separated from disk I/O layer, it requires following functions to lower layer to read/write the physical disk and to get current time. The low level disk I/O module is not a part of FatFs module so that it must be provided by user. The sample drivers are also available in the resources.
- disk_initialize - Initialize disk drive
- disk_status - Get disk status
- disk_read - Read sector(s)
- disk_write - Write sector(s)
- disk_ioctl - Control device dependent features
- get_fattime - Get current time
以下是512M SD1.0卡和4G SDHC卡的测试结果:
**************************************************
Card Type : SD V1
File System Sub Type : FAT16
Total space (Bytes) : 511574016
Available space (Bytes) : 511369216
Physical drive number : 0
Maximum cluster : 62450
Number of free clusters : 62423
Last allocated cluster : 0
Maximum sector size : 512
Number of sectors per cluster : 16
Number of FAT copies : 2
Sectors per fat : 244
File system info sector : 0
Root directory start sector : 729
FAT start sector : 241
Data start sector : 761
**************************************************
Write File Successed: 0:CardInfo.txt, 64:64
Write File Successed: 0:ffext2.ini, 13312:13312
Read File Successed: 0:ffext2.ini, 13312:13312
Write File Successed: 0:ffext1.txt, 13312:13312
**************************************************
Card Type : SD V2HC
File System Sub Type : FAT32
Total space (Bytes) : 3949592576
Available space (Bytes) : 3949588480
Physical drive number : 0
Maximum cluster : 964258
Number of free clusters : 964255
Last allocated cluster : 3
Maximum sector size : 512
Number of sectors per cluster : 8
Number of FAT copies : 2
Sectors per fat : 7534
File system info sector : 1
Root directory start sector : 2
FAT start sector : 36
Data start sector : 15104
**************************************************
Write File Successed: 0:CardInfo.txt, 64:64
Write File Successed: 0:ffext2.ini, 13312:13312
Read File Successed: 0:ffext2.ini, 13312:13312
Write File Successed: 0:ffext1.txt, 13312:13312
以下是移植文件:
用户448030 2013-5-12 14:23
用户177771 2012-2-13 13:14
用户906612 2011-1-19 15:20
用户505847 2010-5-10 17:16