sunwise123的个人空间 https://bbs.21ic.com/?912015 [收藏] [复制] [RSS]

日志

使用STM32CubeMx生成SDIO驱动代码

已有 5201 次阅读2016-12-18 09:14 |个人分类:STM32CubeMx初探|系统分类:ARM| STM32CubeMx, SDIO, SD卡

上一次使用CubeMx生成定时器1的驱动代码,中间发生了一点小波折。感觉CubeMx并没有想象中那么智能,或者是我对CubeMx还是知之甚少。故今天闲下来打算用Cube生成SD卡驱动代码练习一下,算是增进对CubeMx的认识吧。
手上用的开发板是神舟三号,SD卡部分电路如下所示。

所有的Pinout配置项如下:

时钟配置如下:
SDIO模块配置如下:
NVIC配置如下:
至此所有的参数配置工作完成了,接下来生成代码。
添加测试代码部分。
/* USER CODE BEGIN 0 */
uint32_t SD_Wdata[512]={0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19};
uint32_t SD_Rdata[512]={0};
uint16_t SDaddress = 0x0022;
uint8_t error;
/* USER CODE END 0 */

int main(void)
{

  /* USER CODE BEGIN 1 */

  /* USER CODE END 1 */

  /* MCU Configuration----------------------------------------------------------*/

  /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
  HAL_Init();

  /* Configure the system clock */
  SystemClock_Config();

  /* Initialize all configured peripherals */
  MX_GPIO_Init();
  MX_CRC_Init();
  MX_SDIO_SD_Init();

  /* Initialize interrupts */
  MX_NVIC_Init();

  /* USER CODE BEGIN 2 */

  /* USER CODE END 2 */

  /* Infinite loop */
  /* USER CODE BEGIN WHILE */
  while (1)
  {
  /* USER CODE END WHILE */

  /* USER CODE BEGIN 3 */
  error = HAL_SD_WriteBlocks(&hsd, SD_Wdata, SDaddress, 512, 1);
  HAL_Delay(100);
        error = HAL_SD_ReadBlocks(&hsd, SD_Rdata, SDaddress, 512, 1);
  HAL_Delay(100);
               
        while(1);
  }
  /* USER CODE END 3 */

}
测试仿真结果如下:
本次的测试过程非常顺利,期待下一次的学习。


路过

鸡蛋

鲜花

握手

雷人

评论 (0 个评论)