This project is a small test application which implements read and write support for MMC and SD cards. It includes
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.
I used two microcontrollers during development, the Atmel 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.
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 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
ls
mkdir <directory>
rm <file>
sync
touch <file>
write <file> <offset>
The following table shows some typical code sizes in bytes, using the 20061101 release with malloc()/free():
layer | code size | static RAM usage |
---|---|---|
MMC/SD (read-only) | 1576 | 0 |
MMC/SD (read-write) | 2202 | 517 |
Partition | 418 | 0 |
FAT16 (read-only) | 3834 | 0 |
FAT16 (read-write) | 7932 | 0 |
The static RAM in the read-write case is used for buffering memory card access. Without this buffer, implementation would have been much more complicated.
Please note that the numbers above do not include the C library functions used, e.g. malloc()/free() and 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 dynamic RAM is used, as listed in the following table. Alternatively, the same amount of static RAM can be used.
descriptor | dynamic/static RAM |
---|---|
partition | 17 |
filesystem | 26 |
file | 51 |
directory | 47 |
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 fat16_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.