银杏科技有限公司旗下技术文档发布平台 | |||
技术支持电话 | 0379-69926675-801 | ||
技术支持邮件 | Gingko@vip.163.com | ||
版本 | 日期 | 作者 | 修改内容 |
---|---|---|---|
V1.0 | 2020-07-28 | gingko | 初次建立 |
1.在主界面选择File–>New Project 或者直接点击ACCEE TO MCU SELECTOR
2.出现芯片型号选择,搜索自己芯片的型号,双击型号,或者点击Start Project进入配置
在搜索栏的下面,提供的各 种查找方式,可以选择芯片内核,型号,等等,可以帮助你查找芯片。本实验选取的芯片型号为:STM32H750IBKx。
3.配置RCC,使用外部时钟源
4.时基源选择SysTick
5.将PA10,PB7,PB8设置为GPIO_Output
6.引脚模式配置
7.配置USB_OTG_HS
8.配置USB_DEVICE
9.配置SDMMC1
10.时钟源设置,选择外部高速时钟源,配置为最大主频
11.工程文件的设置, 这里就是工程的各种配置 我们只用到有限几个,其他的默认即可 IDE我们使用的是 MDK V5.27
12.点击Code Generator,进行进一步配置
int main(void) { uint8_t sd_state = HAL_OK; HAL_Init(); SystemClock_Config(); i2c.initialize(); axp152.initialize(); axp152.set_dcdc1(3500);//[ARM & FPGA] axp152.set_dcdc2(1200);//[FPGA INT] axp152.set_dcdc3(3300);//[DCOUT3] axp152.set_dcdc4(3300);//[DCOUT4] axp152.set_aldo1(3300);//[BK3] axp152.set_aldo2(3300);//[ALDOOUT2] axp152.set_dldo1(3300);//[BK0] axp152.set_dldo2(3300);//[BK1] HAL_Delay(200); MX_GPIO_Init(); MX_SDMMC1_SD_Init(); MX_USB_DEVICE_Init(); sd_state = HAL_SD_Init(&hsd1); /* 配置SD总线宽度(选择4位模式) */ if (sd_state == HAL_OK) { if (HAL_SD_ConfigWideBusOperation(&hsd1, SDMMC_BUS_WIDE_4B) != HAL_OK) { sd_state = HAL_ERROR; } } LED_ON; while (1) { } }
void MX_SDMMC1_SD_Init(void) { hsd1.Instance = SDMMC1; hsd1.Init.ClockEdge = SDMMC_CLOCK_EDGE_RISING; hsd1.Init.ClockPowerSave = SDMMC_CLOCK_POWER_SAVE_DISABLE; hsd1.Init.BusWide = SDMMC_BUS_WIDE_4B; hsd1.Init.HardwareFlowControl = SDMMC_HARDWARE_FLOW_CONTROL_DISABLE; hsd1.Init.ClockDiv = 10; hsd1.Init.TranceiverPresent = SDMMC_TRANSCEIVER_NOT_PRESENT; if (HAL_SD_Init(&hsd1) != HAL_OK) { Error_Handler(); } }
void HAL_SD_MspInit(SD_HandleTypeDef* sdHandle) { GPIO_InitTypeDef GPIO_InitStruct = {0}; if(sdHandle->Instance==SDMMC1) { /* SDMMC1时钟使能 */ __HAL_RCC_SDMMC1_CLK_ENABLE(); __HAL_RCC_GPIOC_CLK_ENABLE(); __HAL_RCC_GPIOD_CLK_ENABLE(); /**SDMMC1引脚配置 PC12 ------> SDMMC1_CK PC11 ------> SDMMC1_D3 PC10 ------> SDMMC1_D2 PD2 ------> SDMMC1_CMD PC9 ------> SDMMC1_D1 PC8 ------> SDMMC1_D0 */ GPIO_InitStruct.Pin = GPIO_PIN_12|GPIO_PIN_11|GPIO_PIN_10|GPIO_PIN_9 |GPIO_PIN_8; GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; GPIO_InitStruct.Pull = GPIO_NOPULL; GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH; GPIO_InitStruct.Alternate = GPIO_AF12_SDIO1; HAL_GPIO_Init(GPIOC, &GPIO_InitStruct); GPIO_InitStruct.Pin = GPIO_PIN_2; GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; GPIO_InitStruct.Pull = GPIO_NOPULL; GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH; GPIO_InitStruct.Alternate = GPIO_AF12_SDIO1; HAL_GPIO_Init(GPIOD, &GPIO_InitStruct); } }
int8_t STORAGE_Read_HS(uint8_t lun, uint8_t *buf, uint32_t blk_addr, uint16_t blk_len) { uint32_t timeout = 10000; if(HAL_SD_ReadBlocks(&hsd1,(uint8_t*)buf, blk_addr, blk_len, timeout) == USBD_OK){ while(((HAL_SD_GetCardState(&hsd1) == HAL_SD_CARD_TRANSFER ) ? HAL_OK : HAL_ERROR) != HAL_OK) { if (timeout-- == 0) { return -1; } } } return (USBD_OK); }
int8_t STORAGE_Write_HS(uint8_t lun, uint8_t *buf, uint32_t blk_addr, uint16_t blk_len) { uint32_t timeout = 10000; if(HAL_SD_WriteBlocks(&hsd1,(uint8_t*)buf, blk_addr, blk_len, timeout) == USBD_OK){ while(((HAL_SD_GetCardState(&hsd1) == HAL_SD_CARD_TRANSFER ) ? HAL_OK : HAL_ERROR) != HAL_OK) { if (timeout-- == 0) { return -1; } } } return (USBD_OK); }