Visible to Intel only — Ixiasoft
Visible to Intel only — Ixiasoft
15.5. SD/MMC Controller Programming Model
Software and Hardware Restrictions†
Only one data transfer command should be issued at one time. For CE-ATA devices, if CE-ATA device interrupts are enabled (nIEN=0), only one RW_MULTIPLE_BLOCK command (RW_BLK) should be issued; no other commands (including a new RW_BLK) should be issued before the Data Transfer Over status is set for the outstanding RW_BLK.†
Before issuing a new data transfer command, the software should ensure that the card is not busy due to any previous data transfer command. Before changing the card clock frequency, the software must ensure that there are no data or command transfers in progress.†
If the card is enumerated in SDR12 or SDR25 mode, the application must program the use_hold_reg bit[29] in the CMD register to 1’b1.†
This programming should be done for all data transfer commands and non-data commands that are sent to the card. When the use_hold_reg bit is programmed to 1’b0, the SD/MMC controller bypasses the Hold Registers in the transmit path. The value of this bit should not be changed when a Command or Data Transfer is in progress.†
For more information on using the use_hold_reg and the implementation requirements for meeting the card input hold time, refer to the latest version of the Synopsys® DesignWare® Cores Mobile Storage Host Databook.
Avoiding Glitches in the Card Clock Outputs†
To avoid glitches in the card clock outputs (sdmmc_cclk_out), the software should use the following steps when changing the card clock frequency:†
- Before disabling the clocks, ensure that the card is not busy due to any previous data command. To determine this, check for 0 in bit 9 of the STATUS register.†
- Update the Clock Enable register to disable all clocks. To ensure completion of any previous command before this update, send a command to the CIU to update the clock registers by setting:†
- start_cmd bit†
- "update clock registers only" bits†
- "wait_previous data complete"†
Note: Wait for the CIU to take the command by polling for 0 on the start_cmd bit.†
- Set the start_cmd bit to update the Clock Divider or Clock Source register, or both, Send a command to the CIU to update the clock registers. Wait for the CIU to take the command.
- Set start_cmd to update the Clock Enable register in order to enable the required clocks and send a command to the CIU to update the clock registers; wait for the CIU to take the command.†
Reading from a Card in Non-DMA Mode†
When a card is read in non-DMA mode, the Data Transfer Over (RINTSTS[3]) interrupt occurs as soon as the data transfer from the card is over. There still could be some data left in the FIFO, and the RX_WMark interrupt may or may not occur, depending on the remaining bytes in the FIFO. Software should read any remaining bytes upon seeing the Data Transfer Over (DTO) interrupt. While using the external DMA interface for reading from a card, the DTO interrupt occurs only after all the data is flushed to memory by the DMA Interface unit.†
Writing to a Card in External DMA Mode†
While writing to a card in external DMA mode, if an undefined-length transfer is selected by setting the Byte Count register to 0, the DMA logic may request more data than it sends to the card, since it has no way of knowing at which point the software stops the transfer. The DMA request stops as soon as the DTO is set by the CIU.†
Software Issues a Controller_Reset Command†
If the software issues a controller_reset command by setting control register bit[0] to 1, all the CIU state machines are reset; the FIFO is not cleared. The DMA sends all remaining bytes to the host. In addition to a card-reset, if a FIFO reset is also issued, then:†
- Any pending DMA transfer on the bus completes correctly†
- DMA data read is ignored†
- Write data is unknown (x)†
Additionally, if dma_reset is also issued, any pending DMA transfer is abruptly terminated. When the DW-DMA/Non-DW-DMA is used, the DMA controller channel should also be reset and reprogrammed.†
If any of the previous data commands do not properly terminate, then the software should issue the FIFO reset in order to remove any residual data, if any, in the FIFO. After asserting the FIFO reset, you should wait until this bit is cleared.†
Data-Transfer Requirement Between the FIFO and Host†
One data-transfer requirement between the FIFO and host is that the number of transfers should be a multiple of the FIFO data width (F_DATA_WIDTH). For example, if F_DATA_WIDTH = 32 and you want to write only 15 bytes to an SD_MMC_CEATA card (BYTCNT), the host should write 16 bytes to the FIFO or program the DMA to do 16-byte transfers, if external DMA mode is enabled. The software can still program the Byte Count register to only 15, at which point only 15 bytes are transferred to the card. Similarly, when 15 bytes are read from a card, the host should still read all 16 bytes from the FIFO.†
It is recommended that you not change the FIFO threshold register in the middle of data transfers when DW-DMA/Non-DW-DMA mode is chosen.†
Initialization†
Power-On Reset Sequence
- Before enabling power to the card, confirm that the voltage setting to the voltage regulator is correct. †
- Enable power to the card by setting the power enable bit (power_enable) in the power enable register (pwren) to 1. Wait for the power ramp‑up time before proceeding to the next step.†
- Set the interrupt masks by resetting the appropriate bits to 0 in the intmask register.†
- Set the int_enable bit of the ctrl register to 1.†
Note: Intel recommends that you write 0xFFFFFFFF to the rintsts register to clear any pending interrupts before setting the int_enable bit to 1.†
- Discover the card stack according to the card type. For discovery, you must restrict the clock frequency to 400 kHz in accordance with SD/MMC/CE‑ATA standards. For more information, refer to Enumerated Card Stack.†
- Set the clock source assignments. Set the card frequency using the clkdiv and clksrc registers of the controller. For more information, refer to Clock Setup.†
- The following common registers and fields can be set during initialization process:†
- The response timeout field (response_timeout) of the tmout register. A typical value is 0x40.†
- The data timeout field (data_timeout) of the tmout register, highest of the following:†
-
10 * NAC †
NAC = card device total access time†
= 10 * ((TAAC * FOP) + (100 * NSAC))†
where:†
TAAC = Time‑dependent factor of the data access time†
FOP = The card clock frequency used for the card operation†
NSAC = Worst‑case clock rate‑dependent factor of the data access time†
-
Host FIFO buffer latency†
On read: Time elapsed before host starts reading from a full FIFO buffer†
On write: Time elapsed before host starts writing to an empty FIFO buffer†
-
- Debounce counter register (debnce). A typical debounce value is 25 ms.†
- TX watermark field (tx_wmark) of the FIFO threshold watermark register (fifoth). Typically, the threshold value is set to 512, which is half the FIFO buffer depth.†
- RX watermark field (rx_wmark) of the fifoth register. Typically, the threshold value is set to 511.†
These registers do not need to be changed with every SD/MMC/CE‑ATA command. Set them to a typical value according to the SD/MMC/CE‑ATA specifications.
Enumerated Card Stack
- Discovers the connected card †
- Sets the relative Card Address Register (RCA) in the connected card†
- Reads the card specific information†
- Stores the card specific information locally†
The card connected to the controller can be an MMC, CE‑ATA, SD or SDIO (including IO ONLY, MEM ONLY and COMBO) card.
Identifying the Connected Card Type
- Reset the card width 1 or 4 bit (card_width2) and card width 8 bit (card_width1) fields in the ctype register to 0.
- Identify the card type as SD, MMC, SDIO or SDIO-COMBO:
- Send an SD/SDIO IO_SEND_OP_COND (CMD5) command with argument 0 to the card.
- Read resp0 on the controller. The response to the IO_SEND_OP_COND command gives the voltage that the card supports.
- Send the IO_SEND_OP_COND command, with the desired voltage window in the arguments. This command sets the voltage window and makes the card exit the initialization state.
- Check bit 27 in resp0:
- If bit 27 is 0, the SDIO card is IO ONLY. In this case, proceed to step 5.
- If bit 27 is 1, the card type is SDIO COMBO. Continue with the following steps.
- Go to unresolvable-reference.html#lro1415721966101.
- Go to unresolvable-reference.html#lro1415730606426.
- At this point, the software has determined the card type as SD/SDHC, SDIO or SDIO-COMBO. Now it must enumerate the card stack according to the type that has been discovered.
- Set the card clock source frequency to the frequency of identification clock rate, 400 KHz. Use one of the following discovery command sequences:
- For an SD card or an SDIO memory section, send the following SD/SDIO command sequence:
- GO_IDLE_STATE
- SEND_IF_COND
- SD_SEND_OP_COND (ACMD41)
- ALL_SEND_CID (CMD2)
- SEND_RELATIVE_ADDR (CMD3)
- For an SDIO card, send the following command sequence:
- IO_SEND_OP_COND
- If the function count is valid, send the SEND_RELATIVE_ADDR command.
- For an MMC, send the following command sequence:
- GO_IDLE_STATE
- SEND_OP_COND (CMD1)
- ALL_SEND_CID
- SEND_RELATIVE_ADDR
- For an SD card or an SDIO memory section, send the following SD/SDIO command sequence:
- You can change the card clock frequency after discovery by writing a value to the clkdiv register that divides down the sdmmc_clk clock.
The following list shows typical clock frequencies for various types of cards:
- SD memory card, 25 MHz†
- MMC card device, 12.5 MHz†
- Full speed SDIO, 25 MHz†
- Low speed SDIO, 400 kHz†
Card Type is Either SDIO COMBO or Still in Initialization
Only continue with this step if the SDIO card type is COMBO or there is no response received from the previous IO_SEND_OP_COND command. Otherwise, skip to Step 5 in the Identifying the Connected Card Type section.
- Send the SD/SDIO SEND_IF_COND (CMD8) command with the following arguments:
- Bit[31:12] = 0x0 (reserved bits)†
- Bit[11:8] = 0x1 (supply voltage value)†
- Bit[7:0] = 0xAA (preferred check pattern by SD memory cards compliant with SDIO Simplified Specification Version 2.00 and later.)†
Refer to SDIO Simplified Specification Version 2.00 as described on the SD Association website.
- If a response is received to the previous SEND_IF_COND command, the card supports SD High-Capacity, compliant with SD Specifications, Part 1, Physical Layer Simplified Specification Version 2.00.
- If no response is received, proceed to the next decision statement.
- Send the SD_SEND_OP_COND (ACMD41) command with the following arguments:
- Bit[31] = 0x0 (reserved bits)†
- Bit[30] = 0x1 (high capacity status)†
- Bit[29:25] = 0x0 (reserved bits)†
- Bit[24] = 0x1 (S18R ‑‑supports voltage switching for 1.8V)†
- Bit[23:0] = supported voltage range†
- If the previous SD_SEND_OP_COND command receives a response, then the card type is SDHC. Otherwise, the card is MMC or CE-ATA. In either case, skip the following steps and proceed to Step 5 in the Identifying the Connected Card Type section.
- If the initial SEND_IF_COND command does not receive a response, then the card does not support High Capacity SD2.0. Now, proceed to step 3.
- Next, issue the GO_IDLE_STATE command followed by the SD_SEND_OP_COND command with the following arguments:
- Bit[31] = 0x0 (reserved bits)†
- Bit[30] = 0x0 (high capacity status)†
- Bit[29:24] = 0x0 (reserved bits)†
- Bit[23:0] = supported voltage range†
If a response is received to the previous SD_SEND_OP_COND command, the card is SD type. Otherwise, the card is MMC or CE-ATA.
Note: You must issue the SEND_IF_COND command prior to the first SD_SEND_OP_COND command, to initialize the High Capacity SD memory card. The card returns busy as a response to the SD_SEND_OP_COND command when any of the following conditions are true:- The card executes its internal initialization process.
- A SEND_IF_COND command is not issued before the SD_SEND_OP_COND command.
- The ACMD41 command is issued. In the command argument, the Host Capacity Support (HCS) bit is set to 0, for a high capacity SD card.
Determine if Card is a CE-ATA 1.1, CE-ATA 1.0, or MMC Device
Use the following sequence to determine whether the card is a CE-ATA 1.1, CE-ATA 1.0, or MMC device:
Determine whether the card is a CE-ATA v1.1 card device by attempting to select ATA mode.
- Send the SD/SDIO SEND_IF_COND command, querying byte 504 (S_CMD_SET) of the EXT_CSD register block in the external card.
If bit 4 is set to 1, the card device supports ATA mode.
- Send the SWITCH_FUNC (CMD6) command, setting the ATA bit (bit 4) of the EXT_CSD register slice 191 (CMD_SET) to 1.
This command selects ATA mode and activates the ATA command set.
-
You can verify the currently selected mode by reading it back from byte 191 of the EXT_CSD register.
-
Skip to Step 5 in the Identifying the Connected Card Type section.
If the card device does not support ATA mode, it might be an MMC card or a CE-ATA v1.0 card. Proceed to the next section to determine whether the card is a CE-ATA 1.0 card device or an MMC card device.
Determine whether the card is a CE-ATA 1.0 card device or an MMC card device by sending the RW_REG command.
If a response is received and the response data contains the CE-ATA signature, the card is a CE-ATA 1.0 card device. Otherwise, the card is an MMC card device.
Clock Setup
- clksrc
- clkdiv
- clkena
The controller loads these registers when it receives an update clocks command.
Changing the Card Clock Frequency
- Before disabling the clocks, ensure that the card is not busy with any previous data command. To do so, verify that the data_busy bit of the status register (status) is 0.
- Reset the cclk_enable bit of the clkena register to 0, to disable the card clock generation.
- Reset the clksrc register to 0.
- Set the following bits in the cmd register to 1:
- update_clk_regs_only—Specifies the update clocks command†
- wait_prvdata_complete—Ensures that clock parameters do not change until any ongoing data transfer is complete†
- start_cmd—Initiates the command†
- Wait until the start_cmd bit changes to 0. There is no interrupt when the clock modification completes. The controller does not set the command_done bit in the rintsts register upon command completion. The controller might signal a hardware lock error if it already has another command in the queue. In this case, return to Step 4.
For information about hardware lock errors, refer to the "Interrupt and Error Handling" chapter.
- Reset the sdmmc_clk_enable bit to 0 in the enable register of the clock manager peripheral PLL group (perpllgrp).
- In the control register (ctrl) of the SDMMC controller group (sdmmcgrp) in the system manager, set the drive clock phase shift select (drvsel) and sample clock phase shift select (smplsel) bits to specify the required phase shift value.
- Set the sdmmc_clk_enable bit in the Enable register of the clock manager perpllgrp group to 1.
- Set the clkdiv register of the controller to the correct divider value for the required clock frequency.
- Set the cclk_enable bit of the clkena register to 1, to enable the card clock generation.
You can also use the clkena register to enable low‑power mode, which automatically stops the sdmmc_cclk_out clock when the card is idle for more than eight clock cycles.
Controller/DMA/FIFO Buffer Reset Usage
- Controller reset—resets the controller by setting the controller_reset bit in the ctrl register to 1. Controller reset resets the CIU and state machines, and also resets the BIU‑to‑CIU interface. Because this reset bit is self‑clearing, after issuing the reset, wait until this bit changes to 0.†
- FIFO buffer reset—resets the FIFO buffer by setting the FIFO reset bit (fifo_reset) in the ctrl register to 1. FIFO buffer reset resets the FIFO buffer pointers and counters in the FIFO buffer. Because this reset bit is self‑clearing, after issuing the reset, wait until this bit changes to 0.†
- DMA reset—resets the internal DMA controller logic by setting the DMA reset bit (dma_reset) in the ctrl register to 1, which immediately terminates any DMA transfer in progress. Because this reset bit is self‑clearing, after issuing the reset, wait until this bit changes to 0.†
Intel recommends setting the controller_reset, fifo_reset, and dma_reset bits in the ctrl register to 1 first, and then resetting the rintsts register to 0 using another write, to clear any resultant interrupt.
Enabling ECC
- Turn on the ECC hardware, but disable the interrupts.
- Initialize the SRAM in the peripheral.49
- Clear the ECC event bits, because these bits may have become asserted after Step 1.
- Enable the ECC interrupts now that the ECC bits have been set.
Enabling FIFO Buffer ECC
- Verify there are no commands committed to the controller.
- Ensure that the FIFO buffer is initialized. Initialize the FIFO buffer by writing 0 to all 1024 FIFO buffer locations. A FIFO buffer write to any address from 0x200 to the maximum FIFO buffer size is valid.
- Set the SDMMC RAM ECC single and double, correctable error interrupt status bits (serrporta, derrporta, serrportb, and derrportb) to 1 in the sdmmc register in the eccgrp group of the system manager, to clear any previously-detected ECC errors.
- Reset the FIFO buffer by setting the fifo_reset bit to 1 in the ctrl register. This action resets pointers and counters in the FIFO buffer. This reset bit is self-clearing, so after issuing the reset, wait until the bit changes to 0.
- Set the en bit in sdmmc register in eccgrp group of the system manager to 1, to enable ECC for the FIFO buffer in SD/MMC controller.
Non-Data Transfer Commands
When a response is received—either erroneous or valid—the controller sets the command_done bit in the rintsts register to 1. A short response is copied to resp0, while a long response is copied to all four response registers (resp0, resp1, resp2, and resp3).† For long responses, bit 31 of resp3 represents the MSB and bit 0 of resp0 represents the LSB.†
For basic and non‑data transfer commands, perform the following steps:
- Write the cmdarg register with the appropriate command argument parameter.†
- Write the cmd register with the settings in Register Settings for Non-Data Transfer Command.†
- Wait for the controller to accept the command. The start_cmd bit changes to 0 when the command is accepted.†
The following actions occur when the command is loaded into the controller:†
- If no previous command is being processed, the controller accepts the command for execution and resets the start_cmd bit in the cmd register to 0. If a previous command is being processed, the controller loads the new command in the command buffer.†
- If the controller is unable to load the new command—that is, a command is already in progress, a second command is in the buffer, and a third command is attempted—the controller generates a hardware lock error.†
- Check if there is a hardware lock error.†
- Wait for command execution to complete. After receiving either a response from a card or response timeout, the controller sets the command_done bit in the rintsts register to 1. Software can either poll for this bit or respond to a generated interrupt (if enabled).†
- Check if the response timeout boot acknowledge received (bar), rcrc, or re bit is set to 1. Software can either respond to an interrupt raised by these errors or poll the re, rcrc, and bar bits of the rintsts register. If no response error is received, the response is valid. If required, software can copy the response from the response registers.†
cmd Register Settings for Non-Data Transfer Command†
Parameter | Value | Comment |
---|---|---|
start_cmd | 1 |
This bit resets itself to 0 after the command is committed. |
use_hold_reg | 1 or 0 |
Choose the value based on the speed mode used. |
update_clk_regs_only | 0 |
Indicates that the command is not a clock update command |
data_expected | 0 |
Indicates that the command is not a data command |
card_number | 1 |
For one card |
cmd_index | Command Index |
Set this parameter to the command number. For example, set to 8 for the SD/SDIO SEND_IF_COND (CMD8) command. |
send_initialization | 0 or 1 |
1 for card reset commands such as the SD/SDIO GO_IDLE_STATE command 0 otherwise |
stop_abort_cmd | 0 or 1 |
1 for a command to stop data transfer, such as the SD/SDIO STOP_TRANSMISSION command 0 otherwise |
response_length | 0 or 1 |
1 for R2 (long) response 0 for short response |
response_expect | 0 or 1 |
0 for commands with no response, such as SD/SDIO GO_IDLE_STATE, SET_DSR (CMD4), or GO_INACTIVE_STATE (CMD15). 1 otherwise |
Parameter | Value | Comment |
---|---|---|
wait_prvdata_complete | 1 |
Before sending a command on the command line, the host must wait for completion of any data command already in process. Intel recommends that you set this bit to 1, unless the current command is to query status or stop data transfer when transfer is in progress. |
check_response_crc | 1 or 0 |
1 if the response includes a valid CRC, and the software is required to crosscheck the response CRC bits. 0 otherwise |
Data Transfer Commands
Confirming Transfer State
- Issue an SD/SDIO SEND_STATUS (CMD13) command. The controller sends the status of the card as the response to the command.†
- Check the card’s busy status.†
- Wait until the card is not busy.†
- Check the card’s transfer status. If the card is in the stand‑by state, issue an SD/SDIO SELECT/DESELECT_CARD (CMD7) command to place it in the transfer state.†
Busy Signal After CE-ATA RW_BLK Write Transfer
- Issue the SEND_STATUS command and check the MMC busy status before issuing a new CMD60 command†
- Issue the CMD39 command and check the ATA busy status before issuing a new CMD60 command†
For the data transfer commands, software must set the ctype register to the bus width that is programmed in the card.†
Data Transfer Interrupts
- dto—Data transfer is over or terminated. If there is a response timeout error, the controller does not attempt any data transfer and the Data Transfer Over bit is never set.†
- Transmit FIFO data request bit (txdr)—The FIFO buffer threshold for transmitting data is reached; software is expected to write data, if available, into the FIFO buffer.†
- Receive FIFO data request bit (rxdr)—The FIFO buffer threshold for receiving data is reached; software is expected to read data from the FIFO buffer.†
- hto—The FIFO buffer is empty during transmission or is full during reception. Unless software corrects this condition by writing data for empty condition, or reading data for full condition, the controller cannot continue with data transfer. The clock to the card is stopped.†
- bds—The card has not sent data within the timeout period.†
- dcrc—A CRC error occurred during data reception.†
- sbe—The start bit is not received during data reception.†
- ebe—The end bit is not received during data reception, or for a write operation. A CRC error is indicated by the card.†
dcrc, sbe, and ebe indicate that the received data might have errors. If there is a response timeout, no data transfer occurs.†
Single-Block or Multiple-Block Read
- Write the data size in bytes to the bytcnt register. For a multi‑block read, bytcnt must be a multiple of the block size.†
- Write the block size in bytes to the blksiz register. The controller expects data to return from the card in blocks of size blksiz.†
- If the read round trip delay, including the card delay, is greater than half of sdmmc_clk_divided, write to the card threshold control register (cardthrctl) to ensure that the card clock does not stop in the middle of a block of data being transferred from the card to the host. For more information, refer to Card Read Threshold.†
Note: If the card read threshold enable bit (cardrdthren) is 0, the host system must ensure that the RX FIFO buffer does not become full during a read data transfer by ensuring that the RX FIFO buffer is read at a rate faster than that at which data is written into the FIFO buffer. Otherwise, an overflow might occur.†
- Write the cmdarg register with the beginning data address for the data read.†
- Write the cmd register with the parameters listed in cmd Register Settings for Single-Block and Multiple-Block Reads. For SD and MMC cards, use the SD/SDIO READ_SINGLE_BLOCK (CMD17) command for a single‑block read and the READ_MULTIPLE_BLOCK (CMD18) command for a multiple‑block read. For SDIO cards, use the IO_RW_EXTENDED (CMD53) command for both single‑block and multiple‑block transfers. The command argument for (CMD53) is shown in the figure, below. After writing to the cmd register, the controller starts executing the command. When the command is sent to the bus, the Command Done interrupt is generated.†
- Software must check for data error interrupts, reported in the dcrc, bds, sbe, and ebe bits of the rintsts register. If required, software can terminate the data transfer by sending an SD/SDIO STOP command.†
- Software must check for host timeout conditions in the rintsts register:†
- Receive FIFO buffer data request†
- Data starvation from host—the host is not reading from the FIFO buffer fast enough to keep up with data from the card. To correct this condition, software must perform the following steps:†
- Read the fifo_count field of the status register†
- Read the corresponding amount of data out of the FIFO buffer†
In both cases, the software must read data from the FIFO buffer and make space in the FIFO buffer for receiving more data.†
- When a DTO interrupt is received, the software must read the remaining data from the FIFO buffer.†
cmd Register Settings for Single-Block and Multiple-Block Reads†
Parameter | Value | Comment |
---|---|---|
start_cmd | 1 | This bit resets itself to 0 after the command is committed. |
use_hold_reg | 1 or 0 | Choose the value based on speed mode used. |
update_clk_regs_only | 0 | Does not need to update clock parameters |
data_expected | 1 | Data command |
card_number | 1 | For one card |
transfer_mode | 0 | Block transfer |
send_initialization | 0 | 1 for a card reset command such as the SD/SDIO GO_IDLE_STATE command 0 otherwise |
stop_abort_cmd | 0 | 1 for a command to stop data transfer such as the SD/SDIO STOP_TRANSMISSION command 0 otherwise |
send_auto_stop | 0 or 1 | Refer to Auto Stop for information about how to set this parameter. |
read_write | 0 | Read from card |
response_length | 0 | 1 for R2 (long) response 0 for short response |
response_expect | 1 or 0 | 0 for commands with no response, such as SD/SDIO GO_IDLE_STATE, SET_DSR, and GO_INACTIVE_STATE. 1 otherwise |
Parameter | Value | Comment |
---|---|---|
wait_prvdata_complete | 1 or 0 | 0 - sends command to CIU immediately 1 - sends command after previous data transfer ends |
check_response_crc | 1 or 0 | 0 - Controller must not check response CRC 1 - Controller must check response CRC |
cmd_index | Command Index | Set this parameter to the command number. For example, set to 17 or 18 for SD/SDIO READ_SINGLE_BLOCK (CMS17) or READ_MULTIPLE_BLOCK (CMD18) |
Single-Block or Multiple-Block Write
- Write the data size in bytes to the bytcnt register. For a multi‑block write, bytcnt must be a multiple of the block size.†
- Write the block size in bytes to the blksiz register. The controller sends data in blocks of size blksiz each.†
- Write the cmdarg register with the data address to which data must be written.†
- Write data into the FIFO buffer. For best performance, the host software should write data continuously until the FIFO buffer is full.†
- Write the cmd register with the parameters listed in cmd Register Settings for Single-Block and Multiple-Block Write. For SD and MMC cards, use the SD/SDIO WRITE_BLOCK (CMD24) command for a single‑block write and the WRITE_MULTIPLE_BLOCK (CMD25) command for a multiple‑block writes. For SDIO cards, use the IO_RW_EXTENDED command for both single‑block and multiple‑block transfers.†
After writing to the cmd register, the controller starts executing a command if there is no other command already being processed. When the command is sent to the bus, a Command Done interrupt is generated.†
- Software must check for data error interrupts; that is, for dcrc, bds, and ebe bits of the rintsts register. If required, software can terminate the data transfer early by sending the SD/SDIO STOP command.†
- Software must check for host timeout conditions in the rintsts register: †
- Transmit FIFO buffer data request.†
- Data starvation by the host—the controller wrote data to the card faster than the host could supply the data.†
In both cases, the software must write data into the FIFO buffer.†
There are two types of transfers: open‑ended and fixed length.†
- Open‑ended transfers—For an open‑ended block transfer, the byte count is 0. At the end of the data transfer, software must send the STOP_TRANSMISSION command (CMD12).†
- Fixed‑length transfers—The byte count is nonzero. You must already have written the number of bytes to the bytcnt register. The controller issues the STOP command for you if you set the send_auto_stop bit of the cmd register to 1. After completion of a transfer of a given number of bytes, the controller sends the STOP command. Completion of the AUTO_STOP command is reflected by the Auto Command Done interrupt. A response to the AUTO_STOP command is written to the resp1 register. If software does not set the send_auto_stop bit in the cmd register to 1, software must issue the STOP command just like in the open‑ended case.†
When the dto bit of the rintsts register is set, the data command is complete.†
cmd Register Settings for Single-Block and Multiple-Block Write
Parameter | Value | Comment |
---|---|---|
start_cmd | 1 |
This bit resets itself to 0 after the command is committed (accepted by the BIU). |
use_hold_reg | 1 or 0 |
Choose the value based on speed mode used. |
update_clk_regs_only | 0 |
Does not need to update clock parameters |
data_expected | 1 |
Data command |
card_number | 1 |
For one card |
transfer_mode | 0 |
Block transfer |
send_initialization | 0 |
Can be 1, but only for card reset commands such as SD/SDIO GO_IDLE_STATE |
stop_abort_cmd | 0 |
Can be 1 for commands to stop data transfer such as SD/SDIO STOP_TRANSMISSION |
send_auto_stop | 0 or 1 |
Refer to Auto Stop for information about how to set this parameter. |
read_write | 1 |
Write to card |
response_length | 0 |
Can be 1 for R2 (long) responses |
response_expect | 1 |
Can be 0 for commands with no response. For example, SD/SDIO GO_IDLE_STATE, SET_DSR, GO_INACTIVE_STATE etc. |
Parameter | Value | Comment |
---|---|---|
wait_prvdata_complete | 1 |
0—Sends command to the CIU immediately 1—Sends command after previous data transfer ends |
check_response_crc | 1 |
0—Controller must not check response CRC 1—Controller must check response CRC |
cmd_index | Command Index |
Set this parameter to the command number. For example, set to 24 for SD/SDIO WRITE_BLOCK (CMD24) or 25 for WRITE_MULTIPLE_BLOCK (CMD25). |
Stream Read and Write
A stream read requires the same steps as the block read described in Single‑Block or Multiple‑Block Read, except for the following bits in the cmd register:†
- transfer_mode = 0x1 (for stream transfer)†
- cmd_index = 20 (SD/SDIO CMD20)†
A stream write requires the same steps as the block write mentioned in Single‑Block or Multiple‑Block Write, except for the following bits in the cmd register:†
- transfer_mode = 0x1 (for stream transfer)†
- cmd_index = 11 (SD/SDIO CMD11)†
Packed Commands
- SET_BLOCK_COUNT—set block count (number of blocks transferred using the READ_MULTIPLE_BLOCK or WRITE_MULTIPLE_BLOCK command) †
- READ_MULTIPLE_BLOCK—multiple-block read command †
- WRITE_MULTIPLE_BLOCK—multiple-block write command†
Packed commands are organized in packets by the application software and are transparent to the controller.†
Transfer Stop and Abort Commands
STOP_TRANSMISSION (CMD12)
- Set the wait_prvdata_complete bit of the cmd register to 0.†
- Set the stop_abort_cmd in the cmd register to 1, which ensures that the CIU stops.†
The STOP_TRANSMISSION command is a non‑data transfer command.†
ABORT
Sending the ABORT Command
- Set the cmdarg register to include the appropriate command argument parameters listed in cmdarg Register Settings for SD/SDIO ABORT Command.†
- Send the IO_RW_DIRECT command by setting the following fields of the cmd register:†
- Set the command index to 0x52 (IO_RW_DIRECT).†
- Set the stop_abort_cmd bit of the cmd register to 1 to inform the controller that the host aborted the data transfer.†
- Set the wait_prvdata_complete bit of the cmd register to 0.†
- Wait for the cmd bit in the rintsts register to change to 1.†
- Read the response to the IO_RW_DIRECT command (R5) in the response registers for any errors.†
For more information about response values, refer to the Physical Layer Simplified Specification, Version 3.01, available on the SD Association website.
cmdarg Register Settings for SD/SDIO ABORT Command†
Bits | Contents | Value |
---|---|---|
31 |
R/W flag |
1 |
30:28 |
Function number |
0, for access to the CCCR in the card device |
27 |
RAW flag |
1, if needed to read after write |
26 |
Don't care |
- |
25:9 |
Register address |
0x06 |
8 |
Don't care |
- |
7:0 |
Write data |
Function number to abort |
Internal DMA Controller Operations
Internal DMA Controller Initialization
- Set the required bmod register bits: †
- If the internal DMA controller enable bit (de) of the bmod register is set to 0 during the middle of a DMA transfer, the change has no effect. Disabling only takes effect for a new data transfer command.†
- Issuing a software reset immediately terminates the transfer. Prior to issuing a software reset, Intel recommends the host reset the DMA interface by setting the dma_reset bit of the ctrl register to 1.†
- The pbl field of the bmod register is read‑only and a direct reflection of the contents of the DMA multiple transaction size field (dw_dma_multiple_transaction_size) in the fifoth register.†
- The fb bit of the bmod register has to be set appropriately for system performance.†
- Write to the idinten register to mask unnecessary interrupt causes according to the following guidelines:†
- When a Descriptor Unavailable interrupt is asserted, the software needs to form the descriptor, appropriately set its own bit, and then write to the poll demand register (pldmnd) for the internal DMA controller to re‑fetch the descriptor.†
- It is always appropriate for the software to enable abnormal interrupts because any errors related to the transfer are reported to the software.†
- Populate either a transmit or receive descriptor list in memory. Then write the base address of the first descriptor in the list to the internal DMA controller’s descriptor list base address register (dbaddr). The DMA controller then proceeds to load the descriptor list from memory. Internal DMA Controller Transmission Sequences and Internal DMA Controller Reception Sequences describe this step in detail. †
Internal DMA Controller Transmission Sequences
- The host sets up the Descriptor fields (DES0—DES3) for transmission and sets the OWN bit (DES0[31]) to 1. The host also loads the data buffer in system memory with the data to be written to the SD card.†
- The host writes the appropriate write data command (SD/SDIO WRITE_BLOCK or WRITE_MULTIPLE_BLOCK) to the cmd register. The internal DMA controller determines that a write data transfer needs to be performed.†
- The host sets the required transmit threshold level in the tx_wmark field in the fifoth register.†
- The internal DMA controller engine fetches the descriptor and checks the OWN bit. If the OWN bit is set to 0, the host owns the descriptor. In this case, the internal DMA controller enters the suspend state and asserts the Descriptor Unable interrupt. The host then needs to set the descriptor OWN bit to 1 and release the DMA controller by writing any value to the pldmnd register.†
- The host must write the descriptor base address to the dbaddr register.†
- The internal DMA controller waits for the Command Done (CD) bit in the rintsts register to be set to 1, with no errors from the BIU. This condition indicates that a transfer can be done.†
- The internal DMA controller engine waits for a DMA interface request from BIU. The BIU divides each transfer into smaller chunks. Each chunk is an internal request to the DMA. This request is generated based on the transmit threshold value.†
- The internal DMA controller fetches the transmit data from the data buffer in the system memory and transfers the data to the FIFO buffer in preparation for transmission to the card.†
- When data spans across multiple descriptors, the internal DMA controller fetches the next descriptor and continues with its operation with the next descriptor. The Last Descriptor bit in the descriptor DES0 field indicates whether the data spans multiple descriptors or not.†
- When data transmission is complete, status information is updated in the idsts register by setting the ti bit to 1, if enabled. Also, the OWN bit is set to 0 by the DMA controller by updating the DES0 field of the descriptor.†
Internal DMA Controller Reception Sequences
- The host sets up the descriptor fields (DES0—DES3) for reception and sets the OWN (DES0 [31]) to 1.†
- The host writes the read data command to the cmd register in BIU. The internal DMA controller determines that a read data transfer needs to be performed.†
- The host sets the required receive threshold level in the rx_wmark field in the fifoth register.†
- The internal DMA controller engine fetches the descriptor and checks the OWN bit. If the OWN bit is set to 0, the host owns the descriptor. In this case, the internal DMA controller enters suspend state and asserts the Descriptor Unable interrupt. The host then must set the descriptor OWN bit to 1 and release the DMA controller by writing any value to the pldmnd register.†
- The host must write the descriptor base address to the dbaddr register.†
- The internal DMA controller waits for the CD bit in the rintsts register to be set to 1, with no errors from the BIU. This condition indicates that a transfer can be done.†
- The internal DMA controller engine waits for a DMA interface request from the BIU. The BIU divides each transfer into smaller chunks. Each chunk is an internal request to the DMA. This request is generated based on the receive threshold value.†
- The internal DMA controller fetches the data from the FIFO buffer and transfers the data to system memory.†
- When data spans across multiple descriptors, the internal DMA controller fetches the next descriptor and continues with its operation with the next descriptor. The Last Descriptor bit in the descriptor indicates whether the data spans multiple descriptors or not.†
- When data reception is complete, status information is updated in the idsts register by setting the ri bit to 1, if enabled. Also, the OWN bit is set to 0 by the DMA controller by updating the DES0 field of the descriptor.†
Commands for SDIO Card Devices
Suspend and Resume Sequence
The SUSPEND and RESUME operations are implemented by writing to the appropriate bits in the CCCR (Function 0) of the SDIO card. To read from or write to the CCCR, use the controller’s IO_RW_DIRECT command.†
Suspend
- Check if the SDIO card supports the SUSPEND/RESUME protocol by reading the SBS bit in the CCCR at offset 0x08 of the card.†
- Check if the data transfer for the required function number is in process. The function number that is currently active is reflected in the function select bits (FSx) of the CCCR, bits 3:0 at offset 0x0D of the card.†
Note: If the bus status bit (BS), bit 0 at address 0xC, is 1, only the function number given by the FSx bits is valid.†
- To suspend the transfer, set the bus release bit (BR), bit 2 at address 0xC, to 1.†
- Poll the BR and BS bits of the CCCR at offset 0x0C of the card until they are set to 0. The BS bit is 1 when the currently‑selected function is using the data bus. The BR bit remains 1 until the bus release is complete. When the BR and BS bits are 0, the data transfer from the selected function is suspended.†
- During a read‑data transfer, the controller can be waiting for the data from the card. If the data transfer is a read from a card, the controller must be informed after the successful completion of the SUSPEND command. The controller then resets the data state machine and comes out of the wait state. To accomplish this, set the abort read data bit (abort_read_data) in the ctrl register to 1.†
- Wait for data completion, by polling until the dto bit is set to 1 in the rintsts register. To determine the number of pending bytes to transfer, read the transferred CIU card byte count (tcbcnt) register of the controller. Subtract this value from the total transfer size. You use this number to resume the transfer properly.†
Resume
- Check that the card is not in a transfer state, which confirms that the bus is free for data transfer.†
- If the card is in a disconnect state, select it using the SD/SDIO SELECT/DESELECT_CARD command. The card status can be retrieved in response to an IO_RW_DIRECT or IO_RW_EXTENDED command.†
- Check that a function to be resumed is ready for data transfer. Determine this state by reading the corresponding RF<n> flag in CCCR at offset 0x0F of the card. If RF<n> = 1, the function is ready for data transfer.†
Note: For detailed information about the RF<n> flags, refer to SDIO Simplified Specification Version 2.00, available on the SD Association website.†
- To resume transfer, use the IO_RW_DIRECT command to write the function number at the FSx bits in the CCCR, bits 3:0 at offset 0x0D of the card. Form the command argument for the IO_RW_DIRECT command and write it to the cmdarg register. Bit values are listed in the following table.†
Table 148. cmdarg Bit Values for RESUME Command† Bits Content Value 31
R/W flag
1
30:28
Function number
0, for CCCR access
27
RAW flag
1, read after write
26
Don't care
- 25:9
Register address
0x0D
8
Don't care
- 7:0
Write data
Function number that is to be resumed
- Write the block size value to the blksiz register. Data is transferred in units of this block size.†
- Write the byte count value to the bytcnt register. Specify the total size of the data that is the remaining bytes to be transferred. It is the responsibility of the software to handle the data.†
To determine the number of pending bytes to transfer, read the transferred CIU card byte count register (tcbcnt). Subtract this value from the total transfer size to calculate the number of remaining bytes to transfer.†
- Write to the cmd register similar to a block transfer operation. When the cmd register is written, the command is sent and the function resumes data transfer. For more information, refer to Single‑Block or Multiple‑Block Read and Single‑Block or Multiple‑Block Write.†
- Read the resume data flag (DF) of the SDIO card device. Interpret the DF flag as follows:†
- DF=1—The function has data for the transfer and begins a data transfer as soon as the function or memory is resumed.†
- DF=0—The function has no data for the transfer. If the data transfer is a read, the controller waits for data. After the data timeout period, it issues a data timeout error.†
Read-Wait Sequence
Signaling a Stall
- Check if the card supports the read_wait facility by reading the SDIO card’s SRW bit, bit 2 at offset 0x8 in the CCCR.†
- If this bit is 1, all functions in the card support the read_wait facility. Use the SD/SDIO IO_RW_DIRECT command to read this bit.†
- If the card supports the read_wait signal, assert it by setting the read wait bit (read_wait) in the ctrl register to 1.†
- Reset the read_wait bit to 0 in the ctrl register.†
CE-ATA Data Transfer Commands
ATA Task File Transfer Overview
The host software stack must write the task file image to the FIFO buffer before setting the cmdarg and cmd registers in the controller. The host processor then writes the address and byte count to the cmdarg register before setting the cmd register bits.†
For the RW_REG command, there is no CCS from the CE‑ATA card device. †
ATA Task File Transfer Using the RW_MULTIPLE_REGISTER (RW_REG) Command
Implementing ATA Task File Transfer
- Write the data size in bytes to the bytcnt register. bytcnt must equal the block size, because the controller expects a single block transfer.†
- Write the block size in bytes to the blksiz register.†
- Write the cmdarg register with the beginning register address.†
You must set the cmdarg, cmd, blksiz, and bytcnt registers according to the tables in Register Settings for ATA Task File Transfer.†
Register Settings for ATA Task File Transfer
Bit | Value | Comment |
---|---|---|
31 |
1 or 0 |
Set to 0 for read operation or set to 1 for write operation |
30:24 |
0 |
Reserved (bits set to 0 by host processor) |
23:18 |
0 |
Starting register address for read or write (DWORD aligned) |
17:16 |
0 |
Register address (DWORD aligned) |
15:8 |
0 |
Reserved (bits set to 0 by host processor) |
7:2 |
16 |
Number of bytes to read or write (integral number of DWORD) |
1:0 |
0 |
Byte count in integral number of DWORD |
Bit | Value | Comment |
---|---|---|
start_cmd | 1 |
|
ccs_expected | 0 |
CCS is not expected |
read_ceata_device | 0 or 1 |
Set to 1 if RW_BLK or RW_REG read |
update_clk_regs_only | 0 |
No clock parameters update command |
card_num | 0 |
|
send_initialization | 0 |
No initialization sequence |
stop_abort_cmd | 0 |
|
send_auto_stop | 0 |
|
transfer_mode | 0 |
Block transfer mode. Block size and byte count must match number of bytes to read or write |
read_write | 1 or 0 |
1 for write and 0 for read |
data_expected | 1 |
Data is expected |
response_length | 0 |
|
response_expect | 1 |
|
cmd_index | Command index |
Set this parameter to the command number. For example, set to 24 for SD/SDIO WRITE_BLOCK (CMD24) or 25 for WRITE_MULTIPLE_BLOCK (CMD25). |
wait_prvdata_complete | 1 |
|
check_response_crc | 1 |
|
Bit | Value | Comment |
---|---|---|
31:16 |
0 |
Reserved bits set to 0 |
15:0 (block_size) |
16 |
For accessing entire task file (16, 8‑bit registers). Block size of 16 bytes |
Bit | Value | Comment |
---|---|---|
31:0 |
16 |
For accessing entire task file (16, 8‑bit registers). Byte count value of 16 is used with the block size set to 16. |
Reset and Card Device Discovery Overview
The host must follow the existing MMC discovery procedure to negotiate the MMC TRAN state. After completing normal MMC reset and initialization procedures, the host must query the initial ATA task file values using the RW_REG or CMD39 command.†
By default, the MMC block size is 512 bytes—indicated by bits 1:0 of the srcControl register inside the CE‑ATA card device. The host can negotiate the use of a 1 KB or 4 KB MMC block sizes. The card indicates MMC block sizes that it can support through the srcCapabilities register in the MMC; the host reads this register to negotiate the MMC block size. Negotiation is complete when the host controller writes the MMC block size into the srcControl register bits 1:0 of the card.†
ATA Payload Transfer Using the RW_MULTIPLE_BLOCK (RW_BLK) Command
Implementing ATA Payload Transfer
- Write the data size in bytes to the bytcnt register.†
- Write the block size in bytes to the blksiz register. The controller expects a single/multiple block transfer.†
- Write to the cmdarg register to indicate the data unit count.†
Register Settings for ATA Payload Transfer
Bits | Value | Comment |
---|---|---|
31 |
1 or 0 |
Set to 0 for read operation or set to 1 for write operation |
30:24 |
0 |
Reserved (bits set to 0 by host processor) |
23:16 |
0 |
Reserved (bits set to 0 by host processor) |
15:8 |
Data count |
Data Count Unit [15:8] |
7:0 |
Data count |
Data Count Unit [7:0] |
Bits | Value | Comment |
---|---|---|
start_cmd | 1 |
- |
ccs_expected | 1 |
CCS is expected. Set to 1 for the RW_BLK command if interrupts are enabled in CE‑ATA card device (the nIEN bit is set to 0 in the ATA control register) |
read_ceata_device | 0 or 1 |
Set to 1 for a RW_BLK or RW_REG read command |
update_clk_regs_only | 0 |
No clock parameters update command |
card_num | 0 |
- |
send_initialization | 0 |
No initialization sequence |
stop_abort_cmd | 0 |
- |
send_auto_stop | 0 |
- |
transfer_mode | 0 |
Block transfer mode. Byte count must be integer multiple of 4kB. Block size can be 512, 1k or 4k bytes |
read_write | 1 or 0 |
1 for write and 0 for read |
data_expected | 1 |
Data is expected |
response_length | 0 |
- |
response_expect | 1 |
- |
cmd_index | Command index |
Set this parameter to the command number. For example, set to 24 for SD/SDIO WRITE_BLOCK (CMD24) or 25 for WRITE_MULTIPLE_BLOCK (CMD25). |
wait_prvdata_complete | 1 |
|
check_response_crc | 1 |
|
Bits | Value | Comment |
---|---|---|
31:16 |
0 |
Reserved bits set to 0 |
15:0 (block_size) |
512, 1024 or 4096 |
MMC block size can be 512, 1024 or 4096 bytes as negotiated by host |
Bits | Value | Comment |
---|---|---|
31:0 |
<n>*block_size |
Byte count must be an integer multiple of the block size. For ATA media access commands, byte count must be a multiple of 4 KB. (<n>*block_size = <x>*4 KB, where <n> and <x> are integers) |
CE-ATA CCS
Disabling the CCS
- Send a CCSD command—the controller sends the CCSD command to the CE‑ATA card device if the send_ccsd bit is set to 1 in the ctrl register of the controller. This bit can be set only after a response is received for the RW_BLK command.†
- Send an internal stop command—send an internally-generated SD/SDIO STOP_TRANSMISSION (CMD12) command after sending the CCSD pattern. If the send_auto_stop_ccsd bit of the ctrl register is also set to 1 when the controller is set to send the CCSD pattern, the controller sends the internally-generated STOP command to the CMD pin. After sending the STOP command, the controller sets the acd bit in the rintsts register to 1.†
Recovery after CCS Timeout
- Send CCSD command—set the send_ccsd bit in the ctrl register to 1.†
- Send external STOP command—terminate the data transfer between the CE‑ATA card device and the controller. For more information about sending the STOP command, refer to Transfer Stop and Abort Commands.†
- Send internal STOP command—set the send_auto_stop_ccsd bit in the ctrl register to 1, which tells the controller to send the internally-generated STOP command. After sending the STOP command, the controller sets the acd bit in the rintsts register to 1. The send_auto_stop_ccsd bit must be set to 1 along with setting the send_ccsd bit.†
Recovery after I/O Read Transmission Delay (NACIO) Timeout
- If the CCS is expected from the CE‑ATA card device (that is, the ccs_expected bit is set to 1 in the cmd register), follow the steps in Recovery after CCS Timeout.†
- If the CCS is not expected from the CE‑ATA card device, perform the following steps: †
- Send an external STOP command. †
- Terminate the data transfer between the controller and CE‑ATA card device. †
Reduced ATA Command Set
The IDENTIFY DEVICE Command
The host issues a RW_REG command for the ATA command, and the data is retrieved with the RW_BLK command.†
The host controller uses the following settings while sending a RW_REG command for the IDENTIFY DEVICE ATA command. The following list shows the primary bit settings:†
- cmd register setting: data_expected bit set to 0†
- cmdarg register settings: †
- Bit [31] set to 0†
- Bits [7:2] set to 128 †
- All other bits set to 0†
- Task file settings: †
- Command field of the ATA task file set to 0xEC†
- Reserved fields of the task file set to 0†
- bytcnt register and block_size field of the blksiz register: set to 16†
The host controller uses the following settings for data retrieval (RW_BLK command):†
- cmd register settings:†
- ccs_expected set to 1†
- data_expected set to 1†
- cmdarg register settings: †
- Bit [31] set to 0 (read operation) †
- Bits [15:0] set to 1 (data unit count = 1)†
- All other bits set to 0†
- bytcnt register and block_size field of the blksiz register: set to 512†
The READ DMA EXT Command
The WRITE DMA EXT Command
The STANDBY IMMEDIATE Command
For card devices that do not provide a power savings mode, the STANDBY IMMEDIATE command returns a successful status indication. The host issues a RW_REG command for the ATA command, and the status is retrieved with the SD/SDIO CMD39 or RW_REG command. Only the status field of the ATA task file contains the success status; there is no error status.†
The host controller uses the following settings while sending the RW_REG command for the STANDBY IMMEDIATE ATA command: †
- cmd register setting: data_expected bit set to 0†
- cmdarg register settings: †
- Bit [31] set to 1 †
- Bits [7:2] set to 4 †
- All other bits set to 0 †
- Task file settings: †
- Command field of the ATA task file set to 0xE0†
- Reserved fields of the task file set to 0†
- bytcnt register and block_size field of the blksiz register: set to 16 †
The FLUSH CACHE EXT Command
The host issues a RW_REG command for the ATA command, and the status is retrieved with the SD/SDIO CMD39 or RW_REG command. There can be error status for this ATA command, in which case fields other than the status field of the ATA task file are valid.†
The host controller uses the following settings while sending the RW_REG command for the STANDBY IMMEDIATE ATA command:†
- cmd register setting: data_expected bit set to 0 †
- cmdarg register settings: †
- Bit [31] set to 1 †
- Bits [7:2] set to 4†
- All other bits set to 0†
- Task file settings: †
- Command field of the ATA task file set to 0xEA †
- Reserved fields of the task file set to 0†
- bytcnt register and block_size field of the blksiz register: set to 16 †
Card Read Threshold
The card read threshold is required when the round trip delay is greater than half of sdmmc_clk_divided.†
Bus Speed Modes | Round Trip Delay (Delay_R) 50 | Is Stopping of Card Clock Allowed? | Card Read Threshold Required? |
---|---|---|---|
SDR25 |
Delay_R > 0.5 * (sdmmc_clk/4) Delay_R < 0.5 * (sdmmc_clk/4) |
No Yes |
Yes No |
SDR12 |
Delay_R > 0.5 * (sdmmc_clk/4) Delay_R < 0.5 * (sdmmc_clk/4) |
No Yes |
Yes No |
Recommended Usage Guidelines for Card Read Threshold
- The cardthrctl register must be set before setting the cmd register for a data read command.†
- The cardthrctl register must not be set while a data transfer command is in progress.†
- The cardrdthreshold field of the cardthrctl register must be set to at the least the block size of a single or multiblock transfer. A cardrdthreshold field setting greater than or equal to the block size of the read transfer ensures that the card clock does not stop in the middle of a block of data.†
- If the round trip delay is greater than half of the card clock period, card read threshold must be enabled and the card threshold must be set as per guideline 3 to guarantee that the card clock does not stop in the middle of a block of data.†
- If the cardrdthreshold field is set to less than the block size of the transfer, the host must ensure that the receive FIFO buffer never overflows during the read transfer. Overflow can cause the card clock from the controller to stop. The controller is not able to guarantee that the card clock does not stop during a read transfer.†
Card Read Threshold Programming Sequence
To use the card read threshold feature effectively and to guarantee that the card clock does not stop because of a FIFO Full condition in the middle of a block of data being read from the card, follow these steps:†
- Choose a block size that is a multiple of four bytes.†
- Enable card read threshold feature. The card read threshold can be enabled only if the block size for the given transfer is less than or equal to the total depth of the FIFO buffer:†
(block size / 4) ≤ 1024†
- Choose the card read threshold value: †
- If (block size / 4) ≥ 512, choose cardrdthreshold such that:†
- cardrdthreshold ≤ (block size / 4) in bytes†
- If (block size / 4) < 512, choose cardrdthreshold such that:†
- cardrdthreshold = (block size / 4) in bytes†
- If (block size / 4) ≥ 512, choose cardrdthreshold such that:†
- Set the dw_dma_multiple_transaction_size field in the fifoth register to the number of transfers that make up a DMA transaction. For example, size = 1 means 4 bytes are moved. The possible values for the size are 1, 4, 8, 16, 32, 64, 128, and 256 transfers. Select the size so that the value (block size / 4) is evenly divided by the size.†
- Set the rx_wmark field in the fifoth register to the size – 1.†
For example, if your block size is 512 bytes, legal values of dw_dma_multiple_transaction_size and rx_wmark are listed in the following table.
Block Size | dw_dma_multiple_transaction_size | rx_wmark |
---|---|---|
512 |
1 |
0 |
512 |
4 |
3 |
512 |
8 |
7 |
512 |
16 |
15 |
512 |
32 |
31 |
512 |
64 |
63 |
512 |
128 |
127 |
Card Read Threshold Programming Examples
- Choose a block size that is a multiple of 4 (the number of bytes per FIFO location), and less than 4096 (1024 FIFO locations). For example, a block size of 3072 bytes is legal, because 3072 / 4 = 768 FIFO locations.†
- For DMA mode, choose the size so that block size is a multiple of the size. For example size = 128, where block size%size = 0.†
- Set the rx_wmark field = size – 1. For example, the rx_wmark field = 128 – 1 = 127.†
- Because block size > ½ FifoDepth, set the cardrdthreshold field to the block size. For example, the cardrdthreshold field = 3072 bytes.†
Interrupt and Error Handling
- Response and data timeout errors—For response time‑outs, the host software can retry the command. For data time‑outs, the controller has not received the data start bit from the card, so software can either retry the whole data transfer again or retry from a specified block onwards. By reading the contents of the tcbcnt register later, the software can decide how many bytes remain to be copied (read). †
- Response errors—Set to 1 when an error is received during response reception. If the response received is invalid, the software can retry the command. †
- Data errors—Set to 1 when a data receive error occurs. Examples of data receive errors: †
- Data CRC†
- Start bit not found †
- End bit not found †
These errors can be occur on any block. On receipt of an error, the software can issue an SD/SDIO STOP or SEND_IF_COND command, and retry the command for either the whole data or partial data.†
- Hardware locked error—Set to 1 when the controller cannot load a command issued by software. When software sets the start_cmd bit in the cmd register to 1, the controller tries to load the command. If the command buffer already contains a command, this error is raised, and the new command is discarded, requiring the software to reload the command.†
- FIFO buffer underrun/overrun error—If the FIFO buffer is full and software tries to write data to the FIFO buffer, an overrun error is set. Conversely, if the FIFO buffer is empty and the software tries to read data from the FIFO buffer, an underrun error is set. Before reading or writing data in the FIFO buffer, the software must read the FIFO buffer empty bit (fifo_empty) or FIFO buffer full bit (fifo_full) in the status register.†
- Data starvation by host timeout—This condition occurs when software does not service the FIFO buffer fast enough to keep up with the controller. Under this condition and when a read transfer is in process, the software must read data from the FIFO buffer, which creates space for further data reception. When a transmit operation is in process, the software must write data to fill the FIFO buffer so that the controller can write the data to the card.†
- CE‑ATA errors†
- CRC error on command—If a CRC error is detected for a command, the CE‑ATA card device does not send a response, and a response timeout is expected from the controller. The ATA layer is notified that an MMC transport layer error occurred.
- CRC error on command—If a CRC error is detected for a command, the CE‑ATA card device does not send a response, and a response timeout is expected from the controller. The ATA layer is notified that an MMC transport layer error occurred.†
- Write operation—Any MMC transport layer error known to the card device causes an outstanding ATA command to be terminated. The ERR bits are set in the ATA status registers and the appropriate error code is sent to the Error Register (Error) on the ATA card device.†
If the device interrupt bit of the CE‑ATA card (the nIEN bit in the ATA control register) is set to 0, the CCS is sent to the host.†
If the device interrupt bit is set to 1, the card device completes the entire data unit count if the host controller does not abort the ongoing transfer.†
Note: During a multiple‑block data transfer, if a negative CRC status is received from the card device, the data path signals a data CRC error to the BIU by setting the dcrc bit in the rintsts register to 1. It then continues further data transmission until all the bytes are transmitted.† - Read operation—If MMC transport layer errors are detected by the host controller, the host completes the ATA command with an error status. The host controller can issue a CCSD command followed by a STOP_TRANSMISSION (CMD12) command to abort the read transfer. The host can also transfer the entire data unit count bytes without aborting the data transfer.†
Booting Operation for eMMC and MMC
This section describes how to set up the controller for eMMC and MMC boot operation.
Boot Operation by Holding Down the CMD Line
For information about this boot method, refer to the following specifications, available on the JEDEC website:
- JEDEC Standard No. 84‑A441
- JEDEC Standard No. 84‑A44
- JEDEC Standard No. JESD84‑A43
Boot Operation for eMMC Card Device
- The software driver performs the following checks: †
- If the eMMC card device supports boot operation (the BOOT_PARTITION_ENABLE bit is set to 1 in the EXT_CSD register of the eMMC card).†
- The BOOT_SIZE_MULT and BOOT_BUS_WIDTH values in the EXT_CSD register, to be used during the boot process.†
- The software sets the following bits: †
- Sets masks for interrupts, by setting the appropriate bits to 0 in the intmask register.†
- Sets the global int_enable bit of the ctrl register to 1. Other bits in the ctrl register must be set to 0. †
Note: Intel recommends that you write 0xFFFFFFFF to the rintsts and idsts registers to clear any pending interrupts before setting the int_enable bit. For internal DMA controller mode, the software driver needs to unmask all the relevant fields in the idinten register.†
- If the software driver needs to use the internal DMA controller to transfer the boot data received, it must perform the following steps: †
- Set up the descriptors as described in Internal DMA Controller Transmission Sequences and Internal DMA Controller Reception Sequences”. †
- Set the use_internal_dmac bit of the ctrl register to 1.†
- Set the card device frequency to 400 kHz using the clkdiv registers. For more information, refer to Clock Setup.†
- Set the data_timeout field of the tmout register equal to the card device total access time, NAC. †
- Set the blksiz register to 0x200 (512 bytes). †
- Set the bytcnt register to a multiple of 128 KB, as indicated by the BOOT_SIZE_MULT value in the card device.†
- Set the rx_wmark field in the fifoth register. Typically, the threshold value can be set to 512, which is half the FIFO buffer depth.†
- Set the following fields in the cmd register:†
- Initiate the command by setting start_cmd = 1†
- Enable boot (enable_boot) = 1†
- Expect boot acknowledge (expect_boot_ack): †
- If a start‑acknowledge pattern is expected from the card device, set expect_boot_ack to 1.†
- If a start‑acknowledge pattern is not expected from the card device, set expect_boot_ack to 0.†
- Card number (card_number) = 0†
- data_expected = 1†
- Reset the remainder of cmd register bits to 0†
- If no start‑acknowledge pattern is expected from the card device (expect_boot_ack set to 0) proceed to step 12.†
- This step handles the case where a start‑acknowledge pattern is expected (expect_boot_ack was set to 1 in step 9).†
- If the Boot ACK Received interrupt is not received from the controller within 50 ms of initiating the command (step 9), the software driver must set the following cmd register fields: †
- start_cmd = 1†
- Disable boot (disable_boot)= 1†
- card_number = 0 †
- All other fields = 0†
The controller generates a Command Done interrupt after deasserting the CMD pin of the card interface.†
If internal DMA controller mode is used for the boot process, the controller performs the following steps after the Boot ACK Received timeout:†
- The DMA descriptor is closed.†
- The ces bit in the idsts register is set, indicating the Boot ACK Received timeout.†
- The ri bit of the idsts register is not set.†
- If the Boot ACK Received interrupt is received, the software driver must clear this interrupt by writing 1 to the ces bit in the idsts register.†
Within 0.95 seconds of the Boot ACK Received interrupt, the Boot Data Start interrupt must be received from the controller. If this does not occur, the software driver must write the following cmd register fields:†
- start_cmd = 1†
- disable_boot = 1†
- card_number = 0†
- All other fields = 0†
The controller generates a Command Done interrupt after deasserting the CMD pin of the card interface.†
If internal DMA controller mode is used for the boot process, the controller performs the following steps after the Boot ACK Received timeout:†
- The DMA descriptor is closed†
- The ces bit in the idsts register is set, indicating Boot Data Start timeout†
- The ri bit of the idsts register is not set†
- If the Boot Data Start interrupt is received, it indicates that the boot data is being received from the card device. When the DMA engine is not in internal DMA controller mode, the software driver can then initiate a data read from the controller based on the rxdr interrupt bit in the rintsts register.†
In internal DMA controller mode, the DMA engine starts transferring the data from the FIFO buffer to the system memory as soon as the level set in the rx_wmark field of the fifoth register is reached.†
At the end of a successful boot data transfer from the card, the following interrupts are generated:†
- The cmd bit and dto bit in the rintsts register†
- The ri bit in the idsts register, in internal DMA controller mode only†
- If an error occurs in the boot ACK pattern (0b010) or an EBE occurs: †
- The controller automatically aborts the boot process by pulling the CMD line high†
- The controller generates a Command Done interrupt†
- The controller does not generate a Boot ACK Received interrupt†
- The application aborts the boot transfer†
- In internal DMA controller mode:†
- If the software driver creates more descriptors than required by the received boot data, the extra descriptors are not closed by the controller. Software cannot reuse the descriptors until they are closed.†
- If the software driver creates fewer descriptors than required by the received boot data, the controller generates a Descriptor Unavailable interrupt and does not transfer any further data to system memory.†
- If NAC is violated between data block transfers, the DRTO interrupt is asserted. In addition, if there is an error associated with the start or end bit, the SBE or EBE interrupt is also generated.†
The boot operation for eMMC card devices is complete. Do not execute the remaining (step 12).†
- If the Boot ACK Received interrupt is not received from the controller within 50 ms of initiating the command (step 9), the software driver must set the following cmd register fields: †
- This step handles the case where no start‑acknowledge pattern is expected (expect_boot_ack was set to 0 in step 9).†
- If the Boot Data Start interrupt is not received from the controller within 1 second of initiating the command (step 9), the software driver must write the cmd register with the following fields:†
- start_cmd = 1†
- disable_boot = 1†
- card_number = 0†
- All other fields = 0†
The controller generates a Command Done interrupt after deasserting the CMD line of the card. In internal DMA controller mode, the descriptor is closed and the ces bit in the idsts register is set to 1, indicating a Boot Data Start timeout.†
- If a Boot Data Start interrupt is received, it indicates that the boot data is being received from the card device. When the DMA engine is not in internal DMA controller mode, the software driver can then initiate a data read from the controller based on the rxdr interrupt bit in the rintsts register.†
In internal DMA controller mode, the DMA engine starts transferring the data from the FIFO buffer to the system memory as soon as the level specified in the rx_wmark field of the fifoth register is reached.†
At the end of a successful boot data transfer from the card, the following interrupts are generated:†
- The cmd bit and dto bit in the rintsts register†
- The ri bit in the idsts register, in internal DMA controller mode only†
- In internal DMA controller mode:†
- If the software driver creates more descriptors than required by the received boot data, the extra descriptors are not closed by the controller.†
- If the software driver creates fewer descriptors than required by the received boot data, the controller generates a Descriptor Unavailable interrupt and does not transfer any further data to system memory.†
The boot operation for eMMC card devices is complete.†
- If the Boot Data Start interrupt is not received from the controller within 1 second of initiating the command (step 9), the software driver must write the cmd register with the following fields:†
Boot Operation for Removable MMC4.3, MMC4.4 and MMC4.41 Cards
Removable MMC4.3, MMC4.4, and MMC4.41 Differences
- Discover these cards as it would discover MMC4.0/4.1/4.2 cards for the first time†
- Know the card characteristics †
- Decide whether to perform a boot operation or not†
Booting Removable MMC4.3, MMC4.4 and MMC4.41 Cards
- Discover the card as described in Enumerated Card Stack.†
- Read the EXT_CSD register of the card and examine the following fields: †
- BOOT_PARTITION_ENABLE †
- BOOT_SIZE_MULT†
- BOOT_INFO †
- If necessary, the software can manipulate the boot information in the card. †
Note: For more information, refer to “Access to Boot Partition” in the following specifications available on the JEDEC website:
- JEDEC Standard No. 84‑A441
- JEDEC Standard No. 84‑A44
- JEDEC Standard No. JESD84‑A43
- If the host processor needs to perform a boot operation at the next power‑up cycle, it can manipulate the EXT_CSD register contents by using a SWITCH_FUNC command. †
- After this step, the software driver must power down the card by writing to the pwren register. †
- From here on, use the same steps as in Alternative Boot Operation for eMMC Card Devices.†
Alternative Boot Operation
For detailed information about alternative boot operation, refer to the following specifications available on the JEDEC website:
- JEDEC Standard No. 84‑A441
- JEDEC Standard No. 84‑A44
- JEDEC Standard No. JESD84‑A43
Alternative Boot Operation for eMMC Card Devices
- The software driver checks:†
- If the eMMC card device supports alternative boot operation (the BOOT_INFO bit is set to 1 in the eMMC card).†
- The BOOT_SIZE_MULT and BOOT_BUS_WIDTH values in the card device to use during the boot process.†
- The software sets the following bits: †
- Sets masks for interrupts by resetting the appropriate bits to 0 in the intmask register.†
- Sets the int_enable bit of the ctrl register to 1. Other bits in the ctrl register must be set to 0. †
Note: Intel recommends writing 0xFFFFFFFF to the rintsts register and idsts register to clear any pending interrupts before setting the int_enable bit. For internal DMA controller mode, the software driver needs to unmask all the relevant fields in the idinten register.†
- If the software driver needs to use the internal DMA controller to transfer the boot data received, it must perform the following actions: †
- Set up the descriptors as described in Internal DMA Controller Transmission Sequences and Internal DMA Controller Reception Sequences. †
- Set the use internal DMAC bit (use_internal_dmac) of the ctrl register to 1. †
- Set the card device frequency to 400 kHz using the clkdiv registers. For more information, refer to Clock Setup. Ensure that the card clock is running.†
- Wait for a time that ensures that at least 74 card clock cycles have occurred on the card interface.†
- Set the data_timeout field of the tmout register equal to the card device total access time, NAC. †
- Set the blksiz register to 0x200 (512 bytes).†
- Set the bytcnt register to multiples of 128K bytes, as indicated by the BOOT_SIZE_MULT value in the card device.†
- Set the rx_wmark field in the fifoth register. Typically, the threshold value can be set to 512, which is half the FIFO buffer depth.†
- Set the cmdarg register to 0xFFFFFFFA. †
- Initiate the command, by setting the cmd register with the following fields: †
- start_cmd = 1†
- enable_boot = 1†
- expect_boot_ack:†
- If a start‑acknowledge pattern is expected from the card device, set expect_boot_ack to 1.†
- If a start‑acknowledge pattern is not expected from the card device, set expect_boot_ack to 0. †
- card_number = 0 †
- data_expected = 1†
- cmd_index = 0†
- Set the remainder of cmd register bits to 0.†
- If no start‑acknowledge pattern is expected from the card device (expect_boot_ack set to 0) jump to step 15. †
- Wait for the Command Done interrupt.†
- This step handles the case where a start‑acknowledge pattern is expected (expect_boot_ack was set to 1 in step 11).†
- If the Boot ACK Received interrupt is not received from the controller within 50 ms of initiating the command (step 11), the start pattern was not received. The software driver must discontinue the boot process and start with normal discovery. †
If internal DMA controller mode is used for the boot process, the controller performs the following steps after the Boot ACK Received timeout:†
- The DMA descriptor is closed.†
- The ces bit in the idsts register is set to 1, indicating the Boot ACK Received timeout.†
- The ri bit of the idsts register is not set.†
- If the Boot ACK Received interrupt is received, the software driver must clear this interrupt by writing 1 to it. †
Within 0.95 seconds of the Boot ACK Received interrupt, the Boot Data Start interrupt must be received from the controller. If this does not occur, the software driver must discontinue the boot process and start with normal discovery.†
If internal DMA controller mode is used for the boot process, the controller performs the following steps after the Boot ACK Received timeout: †
- The DMA descriptor is closed.†
- The ces bit in the idsts register is set to 1, indicating Boot Data Start timeout.†
- The ri bit of the idsts register is not set.†
- If the Boot Data Start interrupt is received, it indicates that the boot data is being received from the card device. When the DMA engine is not in internal DMA controller mode, the software driver can then initiate a data read from the controller based on the rxdr interrupt bit in the rintsts register.†
In internal DMA controller mode, the DMA engine starts transferring the data from the FIFO buffer to the system memory as soon as the level specified in the rx_wmark field of the fifoth register is reached. †
- The software driver must terminate the boot process by instructing the controller to send the SD/SDIO GO_IDLE_STATE command:†
- Reset the cmdarg register to 0.†
- Set the start_cmd bit of the cmd register to 1, and all other bits to 0.†
- At the end of a successful boot data transfer from the card, the following interrupts are generated: †
- The cmd bit and dto bit in the rintsts register†
- The ri bit in the idsts register, in internal DMA controller mode only†
- If an error occurs in the boot ACK pattern (0b010) or an EBE occurs: †
- The controller does not generate a Boot ACK Received interrupt. †
- The controller detects Boot Data Start and generates a Boot Data Start interrupt. †
- The controller continues to receive boot data. †
- The application must abort the boot process after receiving a Boot Data Start interrupt.†
- In internal DMA controller mode: †
- If the software driver creates more descriptors than required by the received boot data, the extra descriptors are not closed by the controller. †
- If the software driver creates fewer descriptors than required by the received boot data, the controller generates a Descriptor Unavailable interrupt and does not transfer any further data to system memory.†
- If NAC is violated between data block transfers, a DRTO interrupt is asserted. Apart from this, if there is an error associated with the start or end bit, the SBE or EBE interrupt is also generated.†
The alternative boot operation for eMMC card devices is complete. Do not execute the remaining steps (15 and 16). †
- If the Boot ACK Received interrupt is not received from the controller within 50 ms of initiating the command (step 11), the start pattern was not received. The software driver must discontinue the boot process and start with normal discovery. †
- Wait for the Command Done interrupt.†
- This step handles the case where a start‑acknowledge pattern is not expected (expect_boot_ack was set to 0 in step 11). †
- If the Boot Data Start interrupt is not received from the controller within 1 second of initiating the command (step 11), the software driver must discontinue the boot process and start with normal discovery. † In internal DMA controller mode:†
- The DMA descriptor is closed.†
- The ces bit in the idsts register is set to 1, indicating Boot Data Start timeout.†
- The ri bit of the idsts register is not set.†
- If a Boot Data Start interrupt is received, the boot data is being received from the card device. When the DMA engine is not in internal DMA controller mode, the software driver can then initiate a data read from the controller based on the rxdr interrupt bit in the rintsts register.†
In internal DMA controller mode, the DMA engine starts transferring the data from the FIFO buffer to the system memory as soon as the level specified in the rx_wmark field of the fifoth register is reached.†
- The software driver must terminate the boot process by instructing the controller to send the SD/SDIO GO_IDLE_STATE (CMD0) command: †
- Reset the cmdarg register to 0.†
- Set the start_cmd bit in the cmd register to 1, and all other bits to 0.†
- At the end of a successful boot data transfer from the card, the following interrupts are generated: †
- The cmd bit and dto bit in the rintsts register†
- The ri bit in the idsts register, in internal DMA controller mode only †
- In internal DMA controller mode: †
- If the software driver creates more descriptors than required by the received boot data, the extra descriptors are not closed by the controller. †
- If the software driver creates fewer descriptors than required by the received boot data, the controller generates a Descriptor Unavailable interrupt and does not transfer any further data to system memory.†
- If the Boot Data Start interrupt is not received from the controller within 1 second of initiating the command (step 11), the software driver must discontinue the boot process and start with normal discovery. † In internal DMA controller mode:†
The alternative boot operation for eMMC card devices is complete.†
Alternative Boot Operation for MMC4.3 Cards
Removable MMC4.3 Boot Mode Support
- Discover these cards as it would discover MMC4.0/4.1/4.2 cards for the first time †
- Know the card characteristics †
- Decide whether to perform a boot operation or not†
Discovering Removable MMC4.3 Boot Mode Support
- Discover the card as described in Enumerated Card Stack.†
- Read the MMC card device’s EXT_CSD registers and examine the following fields: †
- BOOT_PARTITION_ENABLE †
- BOOT_SIZE_MULT †
- BOOT_INFO †
Note: For more information, refer to "Access to Boot Partition” in JEDEC Standard No. JESD84‑A43, available on the JEDEC website.† - If the host processor needs to perform a boot operation at the next power‑up cycle, it can manipulate the contents of the EXT_CSD registers in the MMC card device, by using a SWITCH_FUNC command. †
- After this step, the software driver must power down the card by writing to the pwren register. †
- From here on, use the same steps as in Alternative Boot Operation for eMMC Card Devices. †
Note: Ignore the EBE if it is generated during an abort scenario.
If a boot acknowledge error occurs, the boot acknowledge received interrupt times out. †
In internal DMA controller mode, the application needs to depend on the descriptor close interrupt instead of the data done interrupt. †
Delay_R = Delay_O + tODLY + Delay_I †
Where: †
Delay_O = sdmmc_clk to sdmmc_cclk_out delay (including I/O pin delay) †
Delay_I = Input I/O pin delay + routing delay to the input register †
tODLY = sdmmc_cclk_out to card output delay (varies across card manufactures and speed modes) †
For the delay numbers needed for above calculation, refer to Arria V Datasheet. †