3.1. SD card command format: 364588 The SD card command consists of 6 bytes (Byte), as follows: Byte 1: 0 1 xxxxxx (command number, defined by instruction flags, CMD39 is 100111, i.e., hexadecimal 0x27, so the first byte of the complete CMD39 is 01100111, i.e., 0x27+0x40). Byte2-5: Command Arguments, some commands have no parameters. Byte6: The first 7 bits are CRC (Cyclic Redundacy Check) check bits, and the last bit is the stop bit 0. 3.2. SD card commands SD card commands are divided into 12 categories, namely class0 to class11. 3.2.1. Class0: (basic command set such as card identification and initialization) CMD0: Reset SD card. CMD1: Read OCR register. CMD9: Read CSD register. CMD10: Read CID register. CMD12: Stop data transmission when reading multiple blocks. CMD13: Read Card_Status register. 3.2.2. Class2 ( Card Reading Command Set ): CMD16: Set the length of the block. CMD17: Read a single block. CMD18: Read multiple blocks , until the host sends CMD12 . 3.2.3.Class4 (Write card command set ): CMD24: Write single block. CMD25: Write multiple blocks. CMD27: Write CSD register. 3.2.4.Class5 (Erase Card Command Set): CMD32:Set the start address of the erase block. CMD33:Set the end address of the erase block. CMD38: Erase the selected block. 3.2.5.Class6 (Write Protect Command Set): CMD28:Set the address of the write-protect block. CMD29:Erase the address of the write-protect block. CMD30: Ask the card for the status of the write protection bits class7:Card lock, unlock function command set. class8:Request for a specific command set. class10 -11 :Reserved. 3.3.SD card workflow First, let's look at how to read and write SD cards on an ARM processor without using an operating system. The process can be divided into three major steps: initializing the SD card, writing to the SD card, and reading the SD card. 3.3.1. Working condition detection The command flow of the card in identification mode is shown in Figure 3.1 (see the standard SD card protocol P24 for the English version) Figure 3.1 Command flow of the card in identification mode 1) Before the host and SD card have any communication, the host does not know the operating voltage range supported by the SD card, and the card does not know whether it supports the voltage currently provided by the host. Therefore, the host first sends a reset command (CMD0) using the default voltage. 2) In order to verify the interface operation status of the SD card, the host sends SEND_IF_COND(CMD8) to obtain the voltage range data supported by the SD card. The SD card checks the working voltage used by the host by detecting the parameter part of CMD8. The host verifies whether the SD card can work under the given voltage by analyzing the parameter part of CMD8 sent back. If the SD card can work under the specified voltage, it returns the command response word of CMD8. If the given voltage is not supported, the SD card will not give any response information and continue to be in the IDLE state. 3) Before sending the ACMD41 command to initialize a high-capacity SD card, you need to forcibly send the CMD8 command. Force the low voltage host to send ACMD41 before sending CMD8. In case the dual voltage SD card does not receive the CMD8 command and works in high voltage state, in this case, the low voltage host must send the CMD8 command to the card, and enters the inactive state after receiving ACMD41. 4) SD_SEND_OP_COND (ACMD) command is designed for the host to identify the SD card or reject the card when the voltage does not match. The host sends the command operand to represent the required voltage window size. If the SD card cannot achieve data transmission within the given range, it will abandon the next bus operation and enter inactivity. The operation status register will also be defined. 5) After the host sends the reset command (CMD0), the host will first send CMD8 and then ACMD41 commands to reinitialize the SD card. 3.3.2.Card Initialization and Identification Processing When the bus is activated, the host begins the card initialization and identification process. The initialization process sets its operating state and begins with the command SD_SEND_OP_COND (ACMD41) that sets the HCS bit in the OCR. The HCS bit is set to 1 to indicate that the host supports High Capacity SD cards. HCS is set to 0, indicating that the host does not support High Capacity SD cards. The card initialization and identification process is shown in Figure 3.2. 364590 Figure 3.2 Card initialization and identification process 3.3.3. Data transmission mode After the card identification mode ends, the host clock fpp (data transmission clock frequency) will be saved as fod (clock in card identification mode) because some cards have restrictions on the operating clock. The host must send SEND_CSD (CMD9) to obtain the card specification data register contents, such as block size, card capacity. The broadcast command SET_DSR (CMD4) configures the driver stage of all identification cards. It programs the DSR register to adapt to the application bus topology, the number of cards on the bus and the data transmission frequency. The flowchart of the SD card data transmission mode (English version of the agreement P26) is shown in Figure 3.3. 364591 Figure 3.3 Flowchart of SD card data transfer mode 1) The CMD7 command is used to select a certain SD card and put it into the Transfer state. In the specified time period, only one card can be in the Transfer state. When a previously selected SD card in the Transfer state receives CMD7, it will release the connection with the controller and enter the Stand-by state. When CMD7 uses the reserved address 0x0000, all SD cards will enter the Stand-by state. 2) All data read commands can be terminated at any time by the Stop command (CMD12). Data transfer will be terminated and the SD card will return to the Transfer state. The read commands include: block read operation (CMD17), multi-block read operation (CMD18), send write protection (CMD30), send scr (ACMD51) and normal command in read mode (CMD56). 3) All data write commands can be terminated at any time by stop command (CMD12). Write commands will also stop before the deselect command (CMD7). Write commands include: block write operations (CMD24, CMD25), programming commands (CMD27), lock/unlock commands (CMD42), and normal commands in write mode (CMD56). 4) Once the data transfer is completed, the SD card will exit the data writing state and enter the Programming state (transfer successful) or Transfer state (transfer failed). Shenzhen Leilong Development Co., Ltd. has been engaged in the NANDFLASH industry for more than 10 years. Currently, it is the agent of ATO Solution small capacity SLC NAND, SPI NAND, MCP, etc. For more information, please contact 28522668; Tel: 1361982107
|