What is this? ------------- This project allows Atmel AVR microcontrollers to read and write flash memory (solid state) cards. The file system is PC compatible, so that data can be transferred between the two. Memory Card Types ----------------- This code supports Multi Media Cards (MMC) and Secure Digital Cards (SD). It was designed for MMC, but the SPI mode for SD seems to be compatible. SD is basically a more advanced version of the MMC. They have two more pins, a write protect switch and more internal functionality. MMC cards will fit into a SD socket but not the other way around. So far I have only tested with a 32MB MMC card and a 32MB SD card. Sizes of up to 1GB should work. Above 1GB FAT32 is needed, which is not yet supported. AVR Types --------- The memory cards only allow write operations with complete sectors of 512 byte. This means the AVR needs to have _more_ RAM than that. (Say at least 1KB). The code size with complete functionality but without debugging is around 7K. It's less when lseek() is not needed. At the current state an ATmeaga32L in an STK500 is used. FAT Types --------- The standard file system type for MMC and SD cards is DOS/Windows FAT. There are three types: FAT12: up to 64 MB FAT16: 16MB to 1GB FAT32: 512MB to 128GB (not yet supported) For performance (speed) reasons it's better to use FAT12 on small cards. The cluster size will be bigger and the FAT needs to be accessed less frequently. The down side is that more space will be wasted when a lot of small files are written. My 32MB cards came formatted with FAT12, but Windows 2000 will format with FAT16 by default. Compiler information -------------------- Compile with avr-gcc, a version of GCC compiled for AVR microcontroller support. Documentation, and links to downloads for Windows and Linux are available from http://www.avrfreaks.net See config.h for the program setup. Interface --------- MMC and SD have a 3.3 volt interface. Do not connect directly to 5 volt! MMC SPI Pad Definition (3.3V) +---+-------+----+------------------------------+--------+ |Pin| Name |Type|SPI Description | AVR | +---+-------+----+------------------------------+--------+ | 1 | /CS | I |Chip Select (Active low) | PB4 | | 2 | DataIn| I |Host to Card Commands and Data|MOSI PB5| | 3 | VSS1 | S |Supply Voltage Ground | GND | | 4 | VDD | S |Supply Voltage | +3.3V | | 5 | CLK | I |Clock |CLK PB7| | 6 | VSS2 | S |Supply Voltage Ground | GND | | 7 |DataOut| O |Card to Host Data and Status |MISO PB6| +---+-------+----+------------------------------+--------+ SD cards have two extra pins one left and one right. Do not connect these. What is supported? ------------------ Let's say what is not (yet) supported: - sub directory access - create new sub directories - create new files with long file names (But an existing LFN file can be opened by using the LFN name.) - lseek() beyond the file end for write access - FAT32 License ------- See: license.txt Why not some other type of memory card? --------------------------------------- - Compact Flash Compact Flash basically has an IDE interface with an electrical interface that is compatible to the PC card standard. The hardware and software interfaces are therefor very complex and not well suited for a small MCU with very little resources. - USB Memory A USB host controller would be needed. Additionally the USB protocols are very complex because they are not just used for memory but all sorts of peripherals. USB memory goes into a connector, not a socket. It sticks out from the device it is connected to. - Sony Memory Stick This is a Sony proprietary standard. One has to pay license fees. I don't know anything about the interface for that reason. - Smart Media Card This card is just slightly bigger and more complex than MMC. It does not have error correction built in though. If one needs to keep track of bad sectors in software things get more difficult. - xD Picture Cards They are nice and small. I admit I did not look into them too much. It seems they are licensed as well. - Multi Media Card (MMC) They are small and offer a very nice and simple SPI interface. Only 4 signals are needed. The physical interface is very simple as well. The contacts are at standard 0.1" distance. If you don't have a real MMC socket, you can just stick it into a PCB connector for development. The software interface has reasonable complexity. It's an open standard and there are no license fees. - Secure Digital Card (SD) The full SD standard is licensed, but SD is basically a more advanced version of the MMC. They have two more pins, a write protect switch and more internal functionality. MMC cards will fit into a SD socket but not the other way around. The SD also has a simple SPI mode that seems to be compatible to the one of the MMC.