MMC/SD驅動(1)

來源:互聯網
上載者:User

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

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.