1、新建工程
2、配置工程
3、启动STM32CUBEMX
(1)配置RCC
(2)配置SDMMC1
4、SD卡初始化
int sdcard_status = 0;
HAL_SD_CardCIDTypedef sdcard_cid;
MX_SDMMC1_SD_Init();
fre = HAL_RCC_GetSysClockFreq();
printf("%d\r\n",fre);
fre = HAL_RCC_GetHCLKFreq();
printf("HCLKFreq = %d\r\n",fre);
fre = HAL_RCC_GetPCLK1Freq();
printf("PCLK1Freq = %d\r\n",fre);
fre = HAL_RCC_GetPCLK2Freq();
printf("PCLK2Freq = %d\r\n",fre);
sdcard_status = HAL_SD_GetCardState(&hsd1);
if(sdcard_status == HAL_SD_CARD_TRANSFER)
{
printf("SD card init ok!\r\n\r\n");
//打印SD卡基本信息
printf("SD card information!\r\n");
printf("CardCapacity: %llu\r\n",((unsigned long long)hsd1.SdCard.BlockSize*hsd1.SdCard.BlockNbr));
printf("CardBlockSize: %d \r\n",hsd1.SdCard.BlockSize);
printf("RCA: %d \r\n",hsd1.SdCard.RelCardAdd);
printf("CardType: %d \r\n",hsd1.SdCard.CardType);
//读取并打印SD卡的CID信息
HAL_SD_GetCardCID(&hsd1,&sdcard_cid);
printf("ManufacturerID: %d \r\n",sdcard_cid.ManufacturerID);
}
else
{
printf("SD card init fail!\r\n" );
}
参考:
https://blog.csdn.net/mculover666/article/details/100555620