Great news – we have decided to open source this project! It can be downloaded for free from GitHub – please follow this link.
Previous customers may continue to use the project under the embedded-code.com licence they purchased under, or apply the new MIT licence we have now released the project under.
MMC (MultiMediaCard) and SD (Secure Digital) memory cards provide a very convenient and inexpensive means of storing large quantities of data on a removable card. However providing a FAT16 / FAT 32 driver for a MMC or SD card, so that the files on the card may also be written and read by a PC is a daunting and complex task.
This MMC / SD card driver provides standard C library fopen() etc functions for FAT16 and FAT32 formatted cards, allowing you to add a MMC / SD card interface to your project with ease.
The driver provides the following main features:-
- Designed for both FAT16 and FAT32 formatted SD, SDHC (high capacity), MMC and MMCplus (high capacity) cards.
- Uses the licence free SPI bus interface for both MMC and SD cards allowing either type to be used with the same driver (the more complex 4 bit interface requires licence payments). Also fully compatible with the miniaturised versions of MMC and SD cards for space critical applications.
- Optimised for embedded designs. Only a single 512 data buffer is required for all operations. (It is not possible to write to MMC or SD cards without a 512 byte buffer as sectors have to be read to local memory, modified and written back as a whole).
- Intelligent use of the local ram sector buffer. Read and writes of sector data only occur when necessary, avoiding unnecessary and slow repeated read or write operations to the card.
- Optimised file delete function for fast deleting of large files. Instead of altering each FAT table entry one at a time, a complete sector of FAT table entries are altered in one operation before writing back to the card, resulting in a large speed improvement.
- Provides the following standard ANSI-C functions:- fopen, fseek, ftell, fgetpos, fsetpos, ffs_rewind, fputc, putc, fgetc, getc, fputs, fgets, fwrite, fread, fflush, fclose, remove, rename, clearer, feof and ferror
- Standard DOS ‘*’ and ‘?’ wildcard characters may be used in file operations.
- Multiple files may be opened, accessed and written at the same time.
- Optional real time clock support for applications that include time keeping. File creation, last modified and last accessed time and date values are automatically stored.
- Detailed project technical manual with a wealth of information on the FAT filing system and the structure of a FAT disk / memory card.
- No reliance on compiler specific libraries.
- Full source code supplied for you to use and modify as required.
Don't think you need FAT32?
You may think that you don’t need anything more than FAT16 for your application if you don’t plan to store more than 2GB of data on a MMC or SD card. After all, many embedded applications only need to store relatively small amounts of data. However MMC and SD cards with capacities greater than 256MB are typically supplied pre-formatted with FAT32. Also Windows will typically format a MMC or SD card with a capacity greater than 32MB as FAT32 by default. This is because FAT32 uses larger volumes more efficiently than FAT16 and is also less susceptible to a single point of failure due to the use of a backup copy of critical data structures in the boot record. Therefore if you use a driver that only supports FAT16 for your application your users will need to find a PC with a MMC or SD card adaptor to re-format larger capacity cards to be FAT16 before they can be used with your device. You also run the risk of increased technical support demands from users who haven’t read your instructions or don't understand how to format a card as FAT16 instead of the default FAT32 and can’t work out why their new MMC or SD card won’t work in your device. Using a driver that supports FAT16 and FAT32 doesn't result in a large amount of additional code space by today’s standards, as the two systems are very similar, and it makes life a lot easier for you and your users.
The driver is designed to support the licence free SPI bus MMC / SD memory card interface.
For full specifications please see the project technical manual.
This source code product is written in C and has been designed to be used with any ANSI compliant C compiler on any platform. Direct compatibility has been tested with the compilers and processors / microcontrollers listed below. Using the driver with other ANSI compliant C compilers and devices should not present significant problems.
Tested with the Rowley Associates CrossWorks for ARM C Compiler, with sample project for the NXP LPC23xx family of 32 bit ARM microcontrollers included.
Tested with the Microchip C18 MPLAB C Compiler for PIC18 family of 8 bit microcontrollers with sample project included. Free version of the compiler available from Microchip.
Tested with the Microchip C30 MPLAB C Compiler for PIC24 family of 16 bit microcontrollers and dsPIC digital signal controllers with sample project included. Free version of the compiler available from Microchip.
Tested with the Microchip C32 MPLAB C Compiler for PIC32 family of 32 bit microcontrollers. Free version of the compiler available from Microchip.
A version of this driver designed for CompactFlash memory cards is also available – click here.