MMC/SD card example application

This project is a small test application which implements read and write support for MMC and SD cards. It includes

The circuit

The curcuit 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.

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.

Pictures

pic01.jpg

The circuit board used to implement and test this application.

pic02.jpg

The MMC/SD card connector on the soldering side of the circuit board.

The software

The software is written in pure standard ANSI-C. Sure, it might not be the smallest or the fastest one, but I think it is quite flexible.

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.

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

Adapting the software to your needs

The only hardware dependent part is the communication layer talking to the memory card. The other parts like partition table and FAT16 support are completely independent, you could use them even for managing Compact Flash cards or standard ATAPI hard disks.

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.

Bugs or comments?

If you have comments or found a bug in the software - there might be some of them - you may contact me per mail at feedback@roland-riegel.de.

Acknowledgements

Thanks go to Ulrich Radig, who explained on his homepage how to interface MMC cards to the Atmel microcontroller (http://www.ulrichradig.de/). I adapted his work for my circuit. Although this is a very simple solution, I had no problems using it.

Copyright 2006-2007 by Roland Riegel

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License version 2 as published by the Free Software Foundation (http://www.gnu.org/copyleft/gpl.html). At your option, you can alternatively redistribute and/or modify the following files under the terms of the GNU Lesser General Public License version 2.1 as published by the Free Software Foundation (http://www.gnu.org/copyleft/lgpl.html):
Generated on Thu Dec 13 19:38:48 2007 for sd-reader by  doxygen 1.5.3-20071008