高中生
最后登录1970-1-1
在线时间 小时
注册时间2016-3-5
|
发表于 2016-6-11 13:42:52
|
显示全部楼层
- <p>
- SD_Error SD_ReadBlock(uint8_t *readbuff, uint64_t ReadAddr, uint16_t BlockSize)
- {
- SD_Error errorstatus = SD_OK;
-
- #if defined (SD_POLLING_MODE)
- uint32_t count = 0, *tempbuff = (uint32_t *)readbuff;
- #endif</p><p> TransferError = SD_OK;
- TransferEnd = 0;
- StopCondition = 0;
-
- SDIO->DCTRL = 0x0; //将 SDIO 数据控制寄存器 (SDIO_DCTRL)清理</p><p>#if defined (SD_DMA_MODE)
- SDIO_ITConfig(SDIO_IT_DCRCFAIL | SDIO_IT_DTIMEOUT | SDIO_IT_DATAEND | SDIO_IT_RXOVERR | SDIO_IT_STBITERR, ENABLE);
- SDIO_DMACmd(ENABLE);
- SD_LowLevel_DMA_RxConfig((uint32_t *)readbuff, BlockSize);
- #endif
-
- if (CardType == SDIO_HIGH_CAPACITY_SD_CARD) //sdhc卡的地址以块为单位,每块512字节, sdsc卡地址为字节地址
- {
- BlockSize = 512;
- // ReadAddr /= 512; //源代码不正确,所以注释掉
- }
- else
- ReadAddr *= BlockSize; //转换为字节地址</p><p> /* Set Block Size for Card cmd16,若是sdsc卡,可以用来设置块大小,若是sdhc卡,块大小为512字节,不受cmd16影响 */
- SDIO_CmdInitStructure.SDIO_Argument = (uint32_t)BlockSize;
- SDIO_CmdInitStructure.SDIO_CmdIndex = SD_CMD_SET_BLOCKLEN; //cmd16:设置块大小
- SDIO_CmdInitStructure.SDIO_Response = SDIO_Response_Short; //r1
- SDIO_CmdInitStructure.SDIO_Wait = SDIO_Wait_No;
- SDIO_CmdInitStructure.SDIO_CPSM = SDIO_CPSM_Enable;
- SDIO_SendCommand(&SDIO_CmdInitStructure);</p><p> errorstatus = CmdResp1Error(SD_CMD_SET_BLOCKLEN);</p><p> if (SD_OK != errorstatus)
- {
- return(errorstatus);
- }
-
- SDIO_DataInitStructure.SDIO_DataTimeOut = SD_DATATIMEOUT;
- SDIO_DataInitStructure.SDIO_DataLength = BlockSize;
- SDIO_DataInitStructure.SDIO_DataBlockSize = (uint32_t) 9 << 4; //设置数据控制寄存器的第4-7位(数据块长度)
- SDIO_DataInitStructure.SDIO_TransferDir = SDIO_TransferDir_ToSDIO;
- SDIO_DataInitStructure.SDIO_TransferMode = SDIO_TransferMode_Block;
- SDIO_DataInitStructure.SDIO_DPSM = SDIO_DPSM_Enable;
- SDIO_DataConfig(&SDIO_DataInitStructure);</p><p> /*!< Send CMD17 READ_SINGLE_BLOCK */
- SDIO_CmdInitStructure.SDIO_Argument = (uint32_t)ReadAddr;
- SDIO_CmdInitStructure.SDIO_CmdIndex = SD_CMD_READ_SINGLE_BLOCK;
- SDIO_CmdInitStructure.SDIO_Response = SDIO_Response_Short;
- SDIO_CmdInitStructure.SDIO_Wait = SDIO_Wait_No;
- SDIO_CmdInitStructure.SDIO_CPSM = SDIO_CPSM_Enable;
- SDIO_SendCommand(&SDIO_CmdInitStructure);</p><p> errorstatus = CmdResp1Error(SD_CMD_READ_SINGLE_BLOCK);</p><p> if (errorstatus != SD_OK)
- {
- return(errorstatus);
- }
- return(errorstatus);
- }
- </p>
复制代码
|
|