1.SD卡命令
static int mmc_test_set_blksize(struct mmc_test_card *test, unsigned size)
{
struct mmc_command cmd;
int ret;
cmd.opcode = MMC_SET_BLOCKLEN; //命令
cmd.arg = size; //參數
cmd.flags = MMC_RSP_R1 | MMC_CMD_AC; //命令類型
ret = mmc_wait_for_cmd(test->card->host, &cmd, 0);
if (ret)
return ret;
return 0;
}
命令類型(BC,BCR,AC,ADTC):
SPI Mode & SD Mode:
The SD Card wakes up in the SD Bus mode. It will enter SPI mode if the CS signal is asserted (negative) during the reception of the reset command (CMD0).
The default command structure/protocol for SPI mode is that CRC checking is disabled. Since the card powers up in SD Bus mode, CMD0 must be followed by a valid CRC byte (even though the command is sent using the SPI structure). Once in SPI mode, CRCs are disabled by default.
2.SD參考程式
//sd卡寫命令//sd send command<br />uint8 MMC_SD_SendCommand(uint8 cmd, uint32 arg)<br />{<br />uint8 r1;<br />uint8 retry=0;</p><p>SPI_WriteByte(0xff);<br />SPI_WriteByte(0xff);<br />SPI_WriteByte(0xff);<br />SPI_WriteByte(0xff);<br />SPI_WriteByte(0xff);<br />SPI_WriteByte(0xff);</p><p>SPI_CS_Assert();</p><p>SPI_WriteByte(cmd | 0x40);//分別寫入命令//send command<br />SPI_WriteByte(arg>>24);<br />SPI_WriteByte(arg>>16);<br />SPI_WriteByte(arg>>8);<br />SPI_WriteByte(arg);<br />SPI_WriteByte(0x95);</p><p>while((r1 = SPI_WriteByte(0xff)) == 0xff)//等待響應,//wait response<br />if(retry++ > 100) break;//逾時退出//time out error</p><p>SPI_CS_Deassert();</p><p>return r1;//返回狀態值//return state<br />}</p><p>//sd卡複位//reset sd card (software)<br />uint8 MMC_SD_Reset(void)<br />{<br />uint8 i;<br />uint8 retry;<br />uint8 r1=0;<br />retry = 0;<br />SPI_Low();</p><p>do<br />{<br />for(i=0;i<100;i++) SPI_WriteByte(0xff);<br />r1 = MMC_SD_SendCommand(0, 0);//發idle命令//send idle command<br />retry++;<br />if(retry>10) return 1;//逾時退出//time out<br />} while(r1 != 0x01);</p><p>retry = 0;<br />do<br />{<br />r1 = MMC_SD_SendCommand(1, 0);//發active命令//send active command<br />retry++;<br />if(retry>100) return 1;//逾時退出//time out<br />} while(r1);<br />SPI_High();<br />r1 = MMC_SD_SendCommand(59, 0);//關crc//disable CRC</p><p>r1 = MMC_SD_SendCommand(16, 512);//設扇區大小512//set sector size to 512<br />return 0;//正常返回//normal return<br />}
3.處理器關於如何識別SDIO、SD、MMC的流程圖(LINUX)
nanjing