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 licence they purchased under, or apply the new MIT licence we have now released the project under.

CompactFlash 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 CompactFlash card, so that the files on the card may also be written and read by a PC is a daunting and complex task.

This CompactFlash card driver provides standard C library fopen() etc functions for FAT16 and FAT32 formatted CompactFlash cards, allowing you to add a CompactFlash card interface to your project with ease.


The driver provides the following main features:-

  • Designed for both FAT16 and FAT32 formatted CompactFlash cards.
  • Optimised for embedded designs. Only a single 512 data buffer is required for all operations. (It is not possible to write to CompactFlash 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 CompactFlash 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 and accessed at the same time.
  • 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 CompactFlash card. After all, many embedded applications only need to store relatively small amounts of data. However CompactFlash cards with capacities greater than 256MB are typically supplied pre-formatted with FAT32. Also Windows will typically format a CompactFlash 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 CompactFlash 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 CompactFlash 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 8 bit CompactFlash card interfaces.
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 Microchip C18 MPLAB C Compiler for PIC18 family of 8 bit microcontrollers with sample project included. Free version of the compiler available from Microchip.


View the project technical manual

A version of this driver designed for MMC (MultiMediaCard) and SD (Secure Digital) memory cards is also available – click here.


We benefit hugely from resources on the web so we decided we should try and give back some of our knowledge and resources to the community by opening up many of our company’s internal notes and libraries through mini sites like this. We hope you find the site helpful.
Please feel free to comment if you can add help to this page or point out issues and solutions you have found, but please note that we do not provide support on this site. If you need help with a problem please use one of the many online forums.


Your email address will not be published. Required fields are marked *