"Linux Drive Learning" SD Card Specification Learning

Source: Internet
Author: User

Summary:

Learn about SD card specifications, including definition, hardware features, data transfer, command system, etc. No code is involved.

This article is written for Linux driver development to help understand the SD card driver and does not involve excessive hardware content.

Outline:

1. SD Card Introduction

2. SD Card Hardware Specification

3. SD Card Directive specification

4. SD Card Register

1. SD Card Introduction 1.1 Various types of memory card/interface

First, let's look at some of the main memory card names we will encounter in SD card-driven Learning:

Sd:security Digital Memory Card, a new generation of multimedia memory cards, high-speed, secure (but security mechanisms seem to be rarely used)
Mmc:multimedia CARD,SD Card, the previous generation of multimedia memory card, has been basically replaced by SD card
emmc:embedded multimedia Card, embedded memory, generally welded on the PCB. Built-in host controller for Unified MMC interface (extended on traditional MMC interface, integrated with whole theory), Nand Flash is eMMC
The Sdio:secure Digital Input and Output CARD,SD standard defines a peripheral interface, which is used by many device modules. such as Wifi,gps,bluetooth

1.2 SD card Features

The following are some of the features of the SD card.

    • Forward-compatible MMC cards: an interface that plugs into an SD card can also be plugged into an MMC card
    • Maximum of 10 stacked cards
    • SD mode and SPI mode
    • Variable clock (0~25mhz), variable voltage (2.0~3.6v)
    • Live Plug and Draw protection
    • Security system, both authentication and "New cryptography" technology

For more features please read the official SD card specification.

2. SD Card Hardware Specification 2.1 SD card Physical interface

is the pin of the SD card and the MMC card:

As you can see, the SD card adds 8, 92 pins to the MMC card, which will be used as data transfer to support SD transfer mode. SD Card supports SD mode (4 data cable) and SPI mode (2 data cable), MMC card only supports SPI mode.

SD card PIN corresponding function: (SD mode)

SD mode: Data parallel transmission, 2 ground, 1 power supply, 1:, 1 command, 4 data cable (4 access) (SD mode command via command line transmission)
SPI mode: Data serial transmission, 2 ground, 1 power supply, 1:, 1 chip Select, 2 data cable (1 in 1 out) (SPI mode command via data cable)

The default refers to SD mode, if no separate description is included. (This article does not involve SPI mode learning)

2.2 SD card connection to the host

The topology diagram of the connection to the host in SD mode and SPI mode is as follows:

In SD mode, the data and command lines are connected separately to the GPIO ports of the host. In SPI mode, the chip line is connected to each GPIO port of the host, and the data line is on the same bus.

Since the SPI mode data cable is on the same bus, the chip selection is required to select different memory cards, and the SD mode is connected to the host, which does not require the chip selection.

3. SD Card Command Specification 3.1 command type

SD card has dozens of kinds of instructions, but is nothing more than some access to information, data transmission functions, and will not be difficult to understand. The specification book has a detailed status conversion diagram, which is described below.

Here are 4 types of instructions:

    • Broadcast instruction, no answer (code BC): After sending such a command, there is no feedback, but the operation has taken effect.
    • Broadcast instructions, answer (code: BCR) The SD card gives feedback after sending such commands. may be some register information, may be
    • Addressing (Point-to-point) instruction (code-named AC): After sending such commands, only the SD card with the specified address will give feedback (the address is unique by requesting the SD card to be released via the command). There is no data transfer at this time on the DAT line.
    • Addressing (Point-to-point) data transfer Instructions (ADTC): After sending such commands, only the address-setting SD card will give feedback. There is data transfer on the DAT line at this time.
3.2 Command Table

The official document divides the commands into several functions. The following lists all the commands, which are for review only and do not need to be remembered for each command:

Basic command: For resetting, switching SD card status, getting related information

Read Block command: Read single, multiple block data, set block length

Write Block command: Write single, multiple block data, set block length

Erase block command: Erase the corresponding block data

Write protection command: Set, cancel the corresponding address of the data write protection, you can make other programs cannot write to the specified address, for protection purposes. Not a lot of things to use.

Lock Card command: Set up, cancel the lock card. You need a password to access the SD card after you lock the card.

Application Special command: CMD55, the command that must be sent before using Acmd; CMD56 is a standard read and write command that reads and writes a block of data.

Sdio command: Reserved for sdio device use (CMD5 is also reserved for sdio devices), in the official SD card document does not specify the purpose

SD card dedicated command: MMC card cannot use these commands, including setting the data bus bit width, get SD card information (register).

3.2 Command/data transfer mode

The transport protocol for the command is roughly as follows:

    • 0 opening, 1 end
    • Big-endian transmission: MSB First, last LSB
    • CRC check

The following diagram is a transmission of both non-responsive and data-free commands:

Very clear and easy to understand, do not dwell on it.

The following picture is a data transfer for multiple-block readings:

When the host sends multiple read commands, the SD card responds first and prepares the data. Once the data is ready to be sent, the CRC check code is added after each block transfer is complete. After transmitting a block and CRC, the data transfer is immediately followed by the next block until the transfer is complete, or the host sends a new command.

SD mode has 4 data lines, one can transmit half a byte, two times a byte. They are transmitted in such a way as:

The same is the first transmission of the MSB, and then the LSB, one pass half a byte, so that the host can be made to make the displacement of the combination of a byte. If each line passes a single byte, it needs to be shifted 8 times to get a complete byte.

3.3 State Transitions

For SD card status conversion diagram. Idle when re-power on:

It looks like this state diagram is complicated, but the process we're going to take is not complicated. The Linux driver initializes the SD card by following these steps:

CMD0 power-on reset to idle (prevent some models from shutting down, such as some FPGA platforms)->acmd41 get the voltage information supported by the SD card (also need to set the voltage via the host controller)->CMD2 get card information-- CMD3 request the SD card to publish the relative address->cmd9 obtain the CSD register, that is, the card's electrical characteristics data (need to use the SD card relative address)->CMD7 Select the corresponding SD card through the relative address, the card into the data transmission transfer State Various CMD for block read and write

3.4 Process Variance

Different kinds of card initialization process is not the same, through the process of differences we can determine the different types of cards.

Sdio:cmd0 after execution cmd5,cmd5 only SDIO types will respond.

Mmc:acmd 41 for Cmd1,acmd class command only the SD or SDIO card responds. So first detect whether it is sdio, and then detect whether it is SD, and finally detect whether it is MMC (the core layer code is also in this order), otherwise there will be false.

4. SD Card Register

SD card A total of 6 registers, we use the more is CID (Card quotient information), RCA (relative address) and OCR (voltage information):

CID: Card information: Manufacturer, OEM, product name, version, production date, CRC check (all registers have, same as), commonly used
RCA: Card address: Released at initialization, used to communicate with host, 0x0000 represents with all cartoon letters, commonly used
DSR: Driver-dependent, bus current size, rise time, Max open time, Min. open time
CSD: Data transfer requirements: Includes read/write time, read/write voltage maximum minimum, write protection, block read/write error
SCR: Feature support, such as CMD support, bus number support
OCR: Supported voltages, commonly used
SSR: Unique features, card type (OTP,SD, etc.), number of first erase blocks
CSR:R1 returns the card status of the instruction, which is used with the transmit card status to the host

The command system has the corresponding instructions to obtain these 6 registers.

Copyright, reproduced Please specify the source:

Http://www.cnblogs.com/sickworm/p/4015932.html

"Linux Drive Learning" SD Card Specification Learning

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.