SD卡知识的内容,在这里就不作介绍了。主要介绍代码的操作步骤:
第一步,新建工程配置RCC 设置外部晶振
第二步:配置sys,设置Debug为:Serial wire下载
第三步:配置SDIO mode 为SD 4 Wide bus
第四步:配置串口打印(usart1) 以上配置参数默认就可以了。
第五步:配置时钟(Clock Configuration)把Input frequency 设置为:8Mhz就可以了。
选择HSE----->PLLCLK 通道.,并把HCLK设置为单片机支持最高时钟我的为180MHZ单击确定就可以了。
第六步:在main.c加入测试函数就可以了。
void SD_Test(void)
{
printf("aaaaaaaaaaaaaaaaaaaaaa\a\n");
/*获取SD卡的基本信息,比如总块数、块大小 */
HAL_SD_CardInfoTypeDef CardInfo;
HAL_SD_GetCardInfo(&hsd, &CardInfo);
printf("BlockNbr = %u\r\n",CardInfo.BlockNbr);
printf("BlockSize = %u\r\n",CardInfo.BlockSize);
printf("LogBlockNbr = %u\r\n",CardInfo.LogBlockNbr);
printf("LogBlockSize = %u\r\n",CardInfo.LogBlockSize);
/*往SD卡某块写入数据处理*/
uint8_t buf1[512] = {0};
int