SD card protocol learning bit
SD CARDS have a concept called operation mode, each of which corresponds to one or more states. The host can make SD CARDS switch between different states by sending commands. SD CARDS accept commands and make different responses according to their current state.
When the system is powered on or SD card is searched, the SD card controller should be in SD card recognition mode. The SD card is also in this mode and Idle state when it is just connected to the system.
SD Card recognition mode: In this mode, the controller will check the SD Card's working voltage range, identify the SD Card type and ask them to send Relative Card Address. These operations are performed on the RESPECTIVE CMD wires of the SD card. All operations will use the default SD card to identify the identification Clock rate.
SD card reset: After sending GO_IDLE_STATE(CMD0) to SD card, all SD CARDS except those in Inactive state will enter Idle state. In Idle state, the CMD line of SD card is in input mode, the default relative address is 0x0000, the default drive register is set as low speed, large drive current capacity.
Working condition detection
Before any communication between the controller and SD card, the controller does not know the working voltage range supported by SD card, so the controller USES the default voltage to send a reset instruction (CMD0), followed by CMD8 instruction, to obtain the working voltage range data supported by SD card. The SD card checks the working voltage used by the controller by detecting the parameter part of CMD8, and the controller verifies whether the SD card can work under the given voltage by analyzing the returned CMD8 parameter part. If the SD card can work at the specified voltage, it sends back the CMD8 command response, which contains check voltage, check pattern. If the SD card does not support the voltage given, the SD card does not give any response and continues in the Idle state. Under PLV2.0(Physical Layer Version2.0), before executing ACMD41 once, CMD8 instruction is executed to initialize SDHC card. SDHC card determines whether the controller supports PLV2.0 protocol based on whether it has received CMD8 instruction. The low-voltage controller also sends CMD8 before the ACMD41 command to avoid SD CARDS that can work in both voltage modes because they do not receive CMD8, and default to work in high-voltage environment, which is mistaken as only supporting high-voltage mode.
The purpose of the SD_SEND_OP_COND(ACMD41) command is to give the SD card controller a mechanism for identifying whether the SD card will work in the range given to Vdd. If the SD card cannot work in the range specified for Vdd, it will be Inactive state. Note that ACMD41 is an application-specific command, so every time an ACMD41 command is issued, it follows an APP_CMD (CMD55) command. The CMD55 command used in Idle State USES the default card relative address (RCA) 0x0000.
Each time the controller sends CMD0 to reset the SD card, a series of initialization operations (CMD8,ACMD41...) must be re-performed. .
If the OCR bit of the ACMD41 instruction is 0, the controller can query each SD card and determine their common operating voltage range. After the ACMD41 instruction is sent as a query, the SD card does not begin the initialization process until the controller sends another ACMD41 instruction.
SD card initialization and identification process:
After the CMD8 command is sent, the FUNCTION of ACMD41 instruction has been expanded to include more HCS in the parameter and more CCS Capacity Status in the response. The HCS parameter is discarded by an SD card that does not respond to the CMD8 command. When the controller sends ACMD41 instruction to a card that does not respond to CMD8, the HCS bit should be set to zero. If an ACMD41 command with HCS bit 0 is sent to an SDHC card, the SDHC card returns a response with its busy identifier always 0, representing the busy state. The HCS identification bit is used to indicate whether the SD card has completed initialization. If not, the HCS is zero, otherwise, 1. If the HCS is 0, the controller will send ACMD41 instruction repeatedly, and the SD card only checks the HCS bit of the ACMD41 instruction received once.
The SD card responding to CMD8 will send a response to ACMD41 instruction that contains the CCS part, and the controller will only check the CCS bit contained in the response with the HCS flag bit 1. CCS=1 indicates it is an SDHC card, otherwise it is a standard SD card.
Controller then send ALL_SEND_CID (CMD2) command, check each card CID (unique card identification) value, has not been identified SD card (in the Ready state) will send the CID values as a response, after sending the CID values, SD card into the state identification (identification state), then the controller sends CMD3 (SEND_RELATIVE_ADDR) command, request the SD card to send a new relative address (RCA), RCA is used for addressing in later data transfer modes. After the RCA is sent. The SD card enters the standby state, where if the controller wants to assign a new RCA to the SD card, it can send another CMD3 command to the SD card. The RCA released after is the real RCA of SD card.
Data transmission mode:
The controller USES a clock frequency of Fod until the end of the SD card recognition mode. In data transfer mode, the controller may use the Fpp frequency. The controller sends a SSEND_CSD (CMD9) command to obtain the description value in the SD Card CSD register (Card Specific Data), for example, block length, Card capacity information, etc. The broadcast command SET_DSR (CMD4) configure the driver phase (??) for each identified SD card. . It writes the relevant information to the SD card's DSR register. The controller's clock frequency also moves from Fod to Fpp at this point. The SET_DSR command is optional.
CMD7 command is used to select an SD card and make it enter the Transfer state. Only one card can be transferred in the specified period of time. When a previously selected SD card in the Transfer state receives CMD7, it will release the connection with the controller and enter the standby state. When CMD7 USES the reserved address 0x0000, all SD CARDS enter the standby state.
The transition relationship of each state in the data transmission mode is summarized as follows:
All data read commands can be terminated at any time by the stop command (CMD12). The data transmission will be terminated and the SD card will return to the Transfer state. Read commands are: block read operation (CMD17), multi-block read operation (CMD18), send write protection (CMD30), send SCR (ACMD51), and common command in read mode (CMD56)
All data write commands can be terminated at any time by the stop command (CMD12). The write command also stops before the deselect command (CMD7). Write command has: piece of write operations (CMD24 CMD25), Programming command (CMD27), lock/unlock command (CMD42) and writing mode of ordinary command (CMD56) on completion of the data transmission, SD card will exit the data writing state, the state of Programming (transmission) or Transfer state (transmission failure) if the piece of write operations were suspended, but the write operation included the length and CRC check it correctly, the data will be programmed to SD card (from cache write to Flash?
The SD card may provide a cache mode, meaning that the controller can then send the next block of data when the write cache is full and the SD card is in Programming state, DAT0 will remain low (BUSY), indicating that it is BUSY
Write CSD, write protection, erase these operations have no cache function, while the SD card is processing these commands, the remaining data transfer commands are ignored. When the SD card is busy and in the Programming state, DAT0 will also be low by the SD card. When the SD card is in the Programming state, the controller is not allowed to send parameter setting commands. The commands to set parameters are: set block length (CMD16), start of eraser block (CMD32), and end of eraser block (CMD33)
At the moment of SD card Programming, reading commands are also not allowed. When another card is transferred from the standby state to the Transfer state, the card operation in the erase and Programming state will not terminate, but it will automatically enter the Disconnect state and release the data line.
A card in Disconnect can Disconnect from this state by sending the CMD7 command into the Programming state, and reactivating the identifier to reset the SD card (using CMD0 or CMD15) will terminate any pending or ongoing Programming operations. This may destroy the SD card data CMD34-37 CMD50, CMD57 remains.