设置时钟频率
设置SDIO
设置fatfs
设置串口
设置DBUG
生成CubeIDE
这个坑爹东西,默认选了4B,4B会报错,需要在这里设置成1B才行!
main函数
添加一下printf重定向到串口
cpp
// 重定向print start
int __io_putchar(int ch)
{
while ((USART1->SR & 0X40) == 0);
USART1->DR = (uint8_t) ch;
return ch;
}
__attribute__((weak)) int _write(int file, char *ptr, int len)
{
int DataIdx;
for (DataIdx = 0; DataIdx < len; DataIdx++)
{
__io_putchar(*ptr++);
}
return len;
}
添加一下打印sd卡信息的函数
cpp
void printf_sdcard_info(void)
{
uint64_t CardCap; //SD卡容�??????
HAL_SD_CardCIDTypeDef SDCard_CID;
HAL_SD_CardInfoTypeDef SDCardInfo;
HAL_SD_GetCardCID(&hsd,&SDCard_CID); //获取CID
HAL_SD_GetCardInfo(&hsd,&SDCardInfo); //获取SD卡信�??????
CardCap=(uint64_t)(SDCardInfo.LogBlockNbr)*(uint64_t)(SDCardInfo.LogBlockSize); //计算SD卡容�??????
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("Card ManufacturerID: %d \r\n",SDCard_CID.ManufacturerID); //制�?�商ID
printf("CardVersion: %d \r\n",(uint32_t)(SDCardInfo.CardVersion)); //卡版本号
printf("Class: %d \r\n",(uint32_t)(SDCardInfo.Class)); //
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)); //卡容�??????
}
运行
能识别到了,在这里想骂一句CubeMX,你特娘的