Understanding SD, SDIO and MMC Interface

 

 

In this blog post i will present the gist of the paper http://www.kaltech.co.il/pdf/Eureka_sd_wp1.pdf ,  It's crucial for anyone willing to understand how removable devices like sd card work, different protocols/functionalities they support.

Secure Digital (SD) memory card today, is one of the most popular non-volatile removable data storage media for consumer applications. It's not intended to remove hard-disk. Hard-disk can still deliver much better speed and memory capacity. SD card is used in applications demanding optimum memory capacity, smaller size, and low end product cost.  The combination of small foot print, lower cost and optimal performance contributed in SD-card's success.
What is MultiMedia Card (MMC)?


MMC and Sd-card share many common features and have the same physical and electrical specifications. The differences between the two standards are mainly on the software level commands. The similarities allow many hosts to accept both MMC and SD cards on the same socket.


Basic SD Protocol




[caption id="" align="aligncenter" width="434"] SD card pinout[/caption]

SD card follows two protocols SD protocol and SPI protocol.
















































microSD Pinout, SD Mode
Pin #Pin NameSignal Function
1DAT2Data Bit 2
2CD/DAT3Card Detect / Data Bit 3
3CMDCommand Line
4VddSupply Voltage 2.7v / 3.6v
5CLKClock
6VssGround
7DAT0Data Bit 0
8DAT1Data Bit 1

















































microSD Pinout, SPI Mode
Pin #Pin NameSignal Function
1NCNo Connect
2/CSChip Select
3DIMaster Out/Slave In (MOSI)
4VddSupply Voltage 2.7v / 3.6v
5CLKClock
6VssGround
7DOMaster In/Slave Out (MISO)
8RSVReserved

So, let's first look at SD protocol:

Command is transferred to and fro via bidirectional CMD  in form of discrete packets of 48 bits. These command packets include command index, argument and CRC bits. Command is always sent via host and received via sd card. Response packets are also of 48 bits. During data transfer, basic unit of transfer is called block, which is usually of 512 bytes and is transferred via all 4 data pins. Also, after each block transfer, 16 bit of CRC data is also sent.

Note that sd card operates in states. Each state has different sets of commands and host can change state via commands. Command and data signals are synchronized via a clock signal. Initially, host uses 400KHz clock to communicate with the card, but it then eventually increase the clock speed during transfer for max. efficiency. Reason: Before initialization host doesn't know whether it's a SD card or a mmc card. Now MMC card by default during initialization works in Open drain mode(100-400KHz) while SD card works in push-pull mode(0-25Mhz). Thus, initially host uses 400KHz to stay compatible with open drain mode.

SD protocol versions



  • SD- version 1

  • SDHC- version 2 Higher data transfer speed + increased capacity

  • SDXC- version 3 even higher capacity




SDIO AND SD COMBO
SD bus specification defines three card types: memory only card, IO card (SDIO) and card combining memory and IO functions (SD combo). Few memory commands were removed while new I/O commands were added.

For example, SDIO card doesn't have a programming state while sd card have.

At a time SDIO card can perform maximum 8 different functions. of which first two typically are user function and system function.






SD BUS ARCHITECTURE


SD bus specification specifies:


  • physical signal interface on SD bus

  • Definition of each command and it's expected response

  • a set of standard registers on sd card

  • internal state and status of the card

  • command sequence for initializing and enabling data transfer


Note that SD bus specification doesn't define the type of memory/IO to be used with sd card or SDIO card. So apart from NAND one can even use any other non volatile memory with sd card. similarly, there's no restriction on the type of I/O function that can be performed by SDIO card.

What make a SD card Host controller?

SD card host controller is a hardware logic between CPU and SD bus. So the host controller has 256 byte register set which is mapped to system's memory / IO space and by reading which CPU can perform following functions:

  • Detect insertion/removal of SD card

  • turn on/off SD card power

  • control SD card clock speed

  • define command arguments and send commands to sd card

  • recieve command response from sd card

  • read/write data from/to sd card

  • interrupt the CPU on different events

  • suspend/resume/terminate data transaction


It can also include DMA support. Host is responsible for providing power(3V3) to sd card a



long with the interrupt to CPU upon insertion of SD card.

SD card Design

Sd card controller handles all physical and data link level functions like command decoding, CRC , response generation etc. In most NAND designs, access to NAND needs to go through a local processor which handles wear and bad block management. SD constoller doesn't directly access the flash chip, it either access the shadow memory or interrupt the SD MPU to read/write data.

How does SPI comes into picture?

Earlier SD cards/MMC supports SPI to communicate/interface with MCU with SPI ports. But now, SPI support if decreased significantly.

How is card insertion/removal or write protection handled?

SD specification supports hot insertion/removal of SD card. Most Common way of detection is simply via two micro switches in SD host controller to check for write protection or insertion/removal.

SD card file-system

By default, SD card doesn't have any file system. It works on RAW blocks of data. It's responsibility of OS to build a file-system on top of RAW space. Follow on to my next post for more details regarding working with raw file-system.

Comments

Popular posts from this blog

Implementing a MMC/SD/SDIO stack using CAM framework(Part 2)

Software licensing : Introduction and it's types