程序设计
根据 SD 卡识别过程和数据传输过程理解 SD 卡驱动函数代码。这部分代码内容也较多,在本文中只对部分核心函数介绍其功能,详细代码可到灵动官网下载参考。
SPIO配置初始化
void SDIO_ConfigInit(void)
{
SDIO_InitTypeDef SDIO_InitStruct;
SDIO_PIN_GPIO_Config();
SDIO_Detect_Pin_Config();
RCC_AHBPeriph
clockCmd(RCC_AHBENR_SDIO, ENABLE);
SDIO_DeInit();
RCC_AHBPeriphClockCmd(RCC_AHBENR_SDIO, DISABLE);
RCC_AHBPeriphClockCmd(RCC_AHBENR_SDIO, ENABLE);
SDIO_ClockSet(0x2F);
SDIO_StructInit(&SDIO_InitStruct);
SDIO_InitStruct.SDIO_OPMSel = SDIO_MMC_CTRL_OPMSel;
SDIO_InitStruct.SDIO_SelPTSM = SDIO_MMC_CTRL_SelSM;
SDIO_InitStruct.SDIO_DATWT = SDIO_MMC_CTRL_DATWT;
SDIO_Init(&SDIO_InitStruct);
SDIO_CRCConfig(SDIO_MMC_CRCCTL_CMD_CRCEN | SDIO_MMC_CRCCTL_DAT_CRCEN, ENABLE);
}
void show_sdcard_info(void)
{
switch(SDCardInfo.CardType) {
case SDIO_STD_CAPACITY_SD_CARD_V1_1:
printf("Card Type:SDSC V1.1\r\n");
break;
case SDIO_STD_CAPACITY_SD_CARD_
v2_0:
printf("Card Type:SDSC V2.0\r\n");
break;
case SDIO_HIGH_CAPACITY_SD_CARD:
printf("Card Type:SDHC V2.0\r\n");
break;
case SDIO_MULTIMEDIA_CARD:
printf("Card Type:MMC Card\r\n");
break;
}
printf("Card ManufacturerID:%d\r\n", SDCardInfo.SD_cid.ManufacturerID); //The manufacturer ID
printf("Card RCA:%d\r\n", SDCardInfo.RCA); //Card relative address
printf("Card Capacity:%d MB\r\n", (u32)(SDCardInfo.CardCapacity >> 20));
printf("Card BlockSize:%d\r\n\r\n", SDCardInfo.CardBlockSize);
}