[Linux driver learning] SD card specification learning, linuxsd card Specification

Source: Internet
Author: User

[Linux driver learning] SD card specification learning, linuxsd card Specification
Abstract:

Learn about SD card specifications, including definitions, hardware features, data transmission, and command systems. No code is involved.

This article is written for Linux driver development to help you understand the SD card driver without involving too much hardware content.

Outline:

1. SD card Introduction

2. SD card hardware Specification

3. SD card instruction Specification

4. SD card register

 

1. SD card Introduction 1.1 various types of storage cards/interfaces

First, let's take a look at the main memory card terms we will encounter in the SD card driver learning:

SD: Security Digital Memory Card, a new generation of Multimedia Storage Card, high speed, Security (but Security mechanisms seem seldom used)
MMC: Multimedia Card, the SD Card's previous-generation Multimedia Storage Card, has been basically replaced by the SD Card
EMMC: Embedded Multimedia Card, Embedded memory, usually soldered on the PCB. Built-in master controller to implement the unified MMC interface (expanded on the traditional MMC interface, integrated with the entire theory), Nand Flash is eMMC
SDIO: Secure Digital Input and Output Card. SD standard defines a peripheral interface, which is used by many device modules. Such as Wifi, GPS, and Bluetooth

1.2 SD card features

The following are some features of the SD card.

  • Forward compatibility with mmccards: interfaces that can be inserted into SD cards can also be inserted into mmccards
  • Up to 10 stacked cards
  • SD mode and SPI Mode
  • Variable clock (0 ~ 25 MHz), variable voltage (2.0 ~ 3.6 V)
  • Live plugging Protection
  • Security system, mutual authentication and "New cryptographic algorithm" Technology

For more features, see the official SD card specifications.

2. SD card hardware specifications 2.1 SD card physical interfaces

Is the SD card and mmccard pin:

As you can see, the SD card adds 8 and 9 pins on the basis of the mmccard. These two pins will be used for data transmission to support the SD transmission mode. The SD card supports SD mode (4 data lines) and SPI mode (2 data lines). The mmccard only supports SPI mode.

Functions of SD card pins: (SD Mode)

 

SD mode: parallel data transmission, 2 locations, 1 power supply, 1 clock, 1 command, 4 data lines (4 in and out) (SD mode commands are transmitted through command lines)
SPI mode: Data serial transmission, 2 locations, 1 power supply, 1 clock, 1 choice, 2 data lines (1 in 1 out) (SPI mode commands are transmitted through data lines)

If there is no separate description, the default mode is SD. (This article does not involve SPI mode learning)

2.2 connection between SD card and host

The following figure shows the topology of the connection to the host in SD and SPI modes:

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

Because the data lines in the SPI mode are on the same bus, you need to select different storage cards separately. The SD mode is connected to the host separately, and no line selection is required.

3. SD card command specification 3.1 command type

There are dozens of commands on the SD card, but they are nothing more than information retrieval and data transmission functions, which are not very difficult to understand. The specification book has a detailed status transition diagram, which will be described below.

The following are four types of commands:

  • Broadcast command, no response (Code: bc): no feedback is provided after such command is sent, but the operation has taken effect.
  • Broadcast command, with a response (code-named 'rb'): After sending such command, the SD card will give feedback. It may be some register information, it may be
  • Addressing (point-to-point) Command (codenamed ac): After sending such commands, only the SD card with the specified address will give feedback (the address is unique when requesting to publish the SD card through the command ). No data is transmitted online.
  • Addressing (point-to-point) data transmission command (adtc): After such commands are sent, only the SD card with the specified address will give feedback. In this case, data is transmitted online at DAT.
3.2 command table

The official documentation divides commands into several functions. The following lists all the commands for reference only. You do not need to remember each command:

Basic commands: Used to reset and switch the SD card status to obtain relevant information

Read block command: read a single or multiple data blocks and set the block length.

Write block command: write a single or multiple block data and set the block Length

Erase block command: erase the corresponding block data

Write Protection Command: setting or canceling write protection for data of the corresponding address prevents other programs from writing data to the specified address for protection purposes. There are not many use cases.

Card lock command: Set and cancel the card lock. After the card is locked, you need a password to access the SD card.

SDIO command: reserved for use by SDIO devices (limit 5 is also reserved for SDIO devices). The specific purpose is not described in the official SD card documentation.

Dedicated SD card commands: The mmccard cannot use these commands, including setting the Data Bus Bit Width and obtaining the SD card information (registers ).

3.2 command/Data Transmission Mode

The command transmission protocol is roughly as follows:

  • Starts with 0 and ends with 1.
  • Big-End transmission: MSB first, and LSB
  • CRC verification

The following figure shows the transmission of two Commands: no response and no data:

It is very clear and easy to understand.

The following figure shows the data transmission of multiple data reads:

When the host sends multiple read commands, the SD card first responds and prepares data. After the data preparation is complete, start sending and add the crc verification code after each block is transmitted. After a block and crc are transmitted, the data of the next block is transmitted until the transmission is completed, or the host sends a new command.

SD mode has four data lines, which can transmit half a byte at a time and one byte at a time. Their transmission methods are as follows:

Similarly, MSB is first transmitted, and then LSB is uploaded, and half a byte is transferred at a time. This allows the host to combine the displacement into one byte. If each line transmits one byte separately, the entire byte can be obtained only after eight shifts.

3.3 status transition

The SD card status conversion chart. Idle status when power-on is restarted:

It seems that this state chart is very complicated. In fact, the process we are going to take is not complicated. The Linux driver performs the following steps to initialize the SD card:

Reset 0 power-on to idle status (to prevent power-off of some models, such as some FPGA platforms)-> ACMD41 to obtain the voltage supported by the SD card (you also need to set the voltage through the host controller) -> CMD2 obtaining Card dealer information-> CMD3 requesting relative address of the SD card-> ipv9 obtaining the CSD register, that is, the card's electrical characteristic data (the relative address of the SD card is required) -> 7. Select the corresponding SD card through the relative address. The card enters the data transmission Transfer State.-> various CMD commands are used to read and write blocks.

3.4 process differences

Different types of cards have different initialization processes. We can identify different types of cards through process differences.

SDIO: Execute limit 5 after limit 0. limit 5 only responds to the SDIO type.

MMC: Switch ACMD 41 to CMD1. ACMD commands only respond to SD or SDIO cards. Therefore, first check whether it is SDIO, then check whether it is SD, and finally check whether it is MMC (this order is also in the core Layer Code). Otherwise, a false positive will occur.

 

4. SD card register

The SD card has 6 registers. We use CID (Card dealer information), RCA (relative address), and OCR (voltage information ):

CID: card information: manufacturer, OEM, product name, version, production date, CRC Check (all registers are available, the same below), commonly used
RCA: Card address: it is released during initialization and used to communicate with the host. 0x0000 indicates to communicate with all cards.
DSR: Driver-related, bus current size, rising time, maximum start time, minimum start time
CSD: data transmission requirements: including read/write time, maximum read/write voltage, write protection, block read/write errors
SCR: feature support, such as CMD support and bus support
OCR: supported voltage, commonly used
SSR: unique features, card type (OTP, SD, etc.), number of erased blocks at a time
CSR: R1 returns the instruction card status. This register is used with the transfer card status to the host.

The command system has corresponding commands to obtain these 6 registers.

 

Copyright. For more information, see the source:

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


How to Learn linux drivers

1) We recommend "linux driver 3th" and "third edition of linux driver programming" for you to read.
2) read the code under the drive of the kernel and refer to the usb
3) understand the hardware and related protocols you want to write the driver.

For your reference.

 
How to Learn about Linux drivers?

First of all, I am familiar with the architecture of ARM and can write ARM to get a bare-board driver. Then it will be easier to read the Linux kernel driver.

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.