This project provides a general purpose library which implements read and write support for MMC, SD and SDHC memory cards. It includes
I used different microcontrollers during development, the ATmega8 with 8kBytes of flash, and its pin-compatible alternative, the ATmega168 with 16kBytes flash. The first one is the one I started with, but when I implemented FAT16 write support, I ran out of flash space and switched to the ATmega168. For FAT32, an ATmega328 is required.
The circuit board is a self-made and self-soldered board consisting of a single copper layer and standard DIL components, except of the MMC/SD card connector.
The connector is soldered to the bottom side of the board. It has a simple eject button which, when a card is inserted, needs some space beyond the connector itself. As an additional feature the connector has two electrical switches to detect wether a card is inserted and wether this card is write-protected.
The circuit board used to implement and test this application.
The MMC/SD card connector on the soldering side of the circuit board.
I implemented an example application providing a simple command prompt which is accessible via the UART at 9600 Baud. With commands similiar to the Unix shell you can browse different directories, read and write files, create new ones and delete them again. Not all commands are available in all software configurations.
cat <file>
cd <directory>
disk
init
ls
mkdir <directory>
rm <file>
sync
touch <file>
write <file> <offset>
The following table shows some typical code sizes in bytes, using the 20090330 release with a buffered read-write MMC/SD configuration, FAT16 and static memory allocation:
layer | code size | static RAM usage |
---|---|---|
MMC/SD | 2410 | 518 |
Partition | 456 | 17 |
FAT16 | 7928 | 188 |
The static RAM is mostly used for buffering memory card access, which improves performance and reduces implementation complexity.
Please note that the numbers above do not include the C library functions used, e.g. some string functions. These will raise the numbers somewhat if they are not already used in other program parts.
When opening a partition, filesystem, file or directory, a little amount of RAM is used, as listed in the following table. Depending on the library configuration, the memory is either allocated statically or dynamically.
descriptor | dynamic/static RAM |
---|---|
partition | 17 |
filesystem | 26 |
file | 53 |
directory | 49 |
By changing the MCU* variables in the Makefile, you can use other Atmel microcontrollers or different clock speeds. You might also want to change the configuration defines in the files fat_config.h, partition_config.h, sd_raw_config.h and sd-reader_config.h. For example, you could disable write support completely if you only need read support.
For further information, visit the project's FAQ page.