Secure Digital / MMC Memory Card FAT16 / FAT32 Driver


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.


Hardware Specifications

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.


View the project technical manual
View the most recent project revision history (useful for past customers to check for any modifications since they received their files)
Please also read our application note regarding SPI data bus signal noise.


Download sample source code files


A version of this driver designed for CompactFlash memory cards is also available – click here.


Why isn't this code free?
You get what you pay for. Even in these days of open source this still holds true. We provide a premium, time saving service which we charge a fair price for. Every detail of our source code and documentation is meticulously designed, tested and presented. We respond to every support request. We save days or weeks of your development time. We provide trustworthy, fully tested solutions. We don't make you release commercially sensitive sections of your products source code or include usage statements in your products documentation as many of the open source licence agreements require. If these things don't matter to you, then Embedded-Code.com is unlikely to be the choice for you. If you can find the perfect open source or free solution for your project then use it, but if all you can find is poorly written, hard to understand, horribly documented or commercially restrictive code then consider what you get from us for a very low one-time cost. After all, no software is really free because your time isn't free.

Why use our code?
We provide the best written source code you can get. Not only is our code robust, fully tested and pounded upon by many customers before you, it's also been designed to be the best written source code available anywhere. Embedded-code.com was born out of the frustration of not being able to find inexpensive, high quality and easy to use embedded source code on the web. Do you want to work through thousands of lines of cryptic gibberish, waste hours having to fight with a free but painful solution, or do you want to work with code and documentation you can quickly and easily understand? We have written this source code to be as easy as possible to understand by programmers of all levels. All code is highly commented with no lazy programming techniques and all function, variable and constant names are fully descriptive to help you modify and expand the code with ease.

Companies we have supplied our source code drivers to include:


This project may be purchased with the following licence options:-

Private Licence A single named user may use and modify the purchased source code for non-commercial purposes only (i.e. for personal experimentation).
Technical support is available for a period of 1 month from purchase. Free upgrades are available for a period of 3 months from purchase
Commercial Licence A single named user may use and modify the purchased source code in an unlimited number of commercial products without any royalty fees payable.
Technical support and free upgrades are available for a period of 12 months from purchase (11 months for licence upgrades).

Please ensure that you read our full licence agreement before purchasing. All Source Code products are delivered by email.

New Customers
BUY NOW
Purchase Private Use Licence £55.00 Convert to: $(USD), €(EUR)
BUY NOW
Purchase Commercial Use Licence £100.00 Convert to: $(USD), €(EUR)
Previous Customers
UPGRADE NOW
Upgrade Private Use Licence To Commercial Use Licence £65.00 Convert to: $(USD), €(EUR)
RENEW NOW
Renew Existing Licence Upgrades & Support (Private or Commercial) £25.00 Convert to: $(USD), €(EUR)
REQUEST NOW
Receive Latest Version Of The Project Files