1. SDMMC配置,SDMMC hardware flow control使能 GPIO都拉高
2.获取状态和SD卡信息
char GetStatus() { int sdcard_status = 0; sdcard_status = HAL_SD_GetCardState(&hsd1); if(sdcard_status != HAL_SD_CARD_TRANSFER) { return 1; } return 0; } char GetInfo() { int sdcard_status = 0; sdcard_status = HAL_SD_GetCardState(&hsd1); if(sdcard_status == HAL_SD_CARD_TRANSFER) { uint64_t CardCap; HAL_SD_CardCIDTypeDef SDCard_CID; HAL_SD_CardInfoTypeDef SDCardInfo; HAL_SD_GetCardInfo(&hsd1,&SDCardInfo); CardCap=(uint64_t)(SDCardInfo.LogBlockNbr)*(uint64_t)(SDCardInfo.LogBlockSize); switch(SDCardInfo.CardType) { case CARD_SDSC: { if(SDCardInfo.CardVersion == CARD_V1_X) printf("Card Type:SDSC V1\r\n"); else if(SDCardInfo.CardVersion == CARD_V2_X) printf("Card Type:SDSC V2\r\n"); } break; case CARD_SDHC_SDXC:printf("Card Type:SDHC\r\n");break; default:break; } printf("CardVersion: %d \r\n",(uint32_t)(SDCardInfo.CardVersion)); //SD鍗$増鏈�??�?? printf("Class: %d \r\n",(uint32_t)(SDCardInfo.Class)); //SD鍗$被锟�???????? printf("Card RCA(RelCardAdd):%d \r\n",SDCardInfo.RelCardAdd); //鍗$浉�?�瑰湴锟�???????? printf("Card BlockNbr: %d \r\n",SDCardInfo.BlockNbr); //鍧楁暟锟�???????? printf("Card BlockSize: %d \r\n",SDCardInfo.BlockSize); //鍧楀ぇ锟�???????? printf("LogBlockNbr: %d \r\n",(uint32_t)(SDCardInfo.LogBlockNbr)); //閫昏緫鍧楁暟锟�?????? printf("LogBlockSize: %d \r\n",(uint32_t)(SDCardInfo.LogBlockSize)); //閫昏緫鍧�??ぇ锟�???????? printf("Card Capacity: %d MB\r\n",(uint32_t)(CardCap>>20)); //SD鍗�?�锟�?????? HAL_SD_GetCardCID(&hsd1,&SDCard_CID); //鑾峰彇CID printf("Card ManufacturerID: %d \r\n",SDCard_CID.ManufacturerID); //鍒讹�???锟藉晢ID return 0; } else { printf("SD card init fail! \r\n" ); return 1; } }
标签:HAL,SDCardInfo,sdcard,SDMMC,调试,printf,Card,SD From: https://www.cnblogs.com/boring-luobo/p/17811878.html