银杏科技有限公司旗下技术文档发布平台 | |||
技术支持电话 | 0379-69926675-801 | ||
技术支持邮件 | Gingko@vip.163.com | ||
版本 | 日期 | 作者 | 修改内容 |
---|---|---|---|
V1.0 | 2020-03-23 | gingko | 初次建立 |
1.在主界面选择File–>New Project 或者直接点击ACCEE TO MCU SELECTOR 2.出现芯片型号选择,搜索自己芯片的型号,双击型号,或者点击Start Project进入配置 在搜索栏的下面,提供的各 种查找方式,可以选择芯片内核,型号,等等,可以帮助你查找芯片。本实验选取的芯片型号为:STM32H750IBKx。 3.配置RCC,使用外部时钟源 4.时基源选择SysTick 5.将PA10,PB7,PB8,PD4,PI4,PI8设置为GPIO_Output,PC13,PD4设置为GPIO_Input 6.引脚模式配置 7.配置串口 在NVIC Settings一栏使能接收中断 引脚配置 8.配置USB_OTG_HS 9.配置USB_HOST 10.配置FATFS 11.时钟源设置,选择外部高速时钟源,配置为最大主频 12.工程文件的设置, 这里就是工程的各种配置 我们只用到有限几个,其他的默认即可 IDE我们使用的是 MDK V5.27 13.点击Code Generator,进行进一步配置
int main(void) { HAL_Init(); SystemClock_Config(); i2c.initialize(); axp152.initialize(); axp152.set_dcdc1(3500);//[ARM & FPGA BK1/2/6 &OTHER] axp152.set_dcdc2(1200);//[FPGA INT & PLL D] axp152.set_aldo1(2500);//[FPGA PLL A] axp152.set_dcdc4(3300);//[POWER_OUTPUT] axp152.set_dcdc3(3300);//[FPGA BK4][Adjustable] axp152.set_aldo2(3300);//[FPGA BK3][Adjustable] axp152.set_dldo1(3300);//[FPGA BK7][Adjustable] axp152.set_dldo2(3300);//[FPGA BK5][Adjustable] HAL_Delay(200); MX_GPIO_Init(); MX_FATFS_Init(); MX_USB_HOST_Init(); MX_USART2_UART_Init(); LED_ON; usart2.printf("\x0c"); //清屏 usart2.printf("\033[1;32;40m"); //设置终端字体为绿色 usart2.printf("\r\nHello, I am iCore4T.\r\n"); while (1) { MX_USB_HOST_Process(); }
//FPGA PS #define NCONFIG_ON HAL_GPIO_WritePin(GPIOC, GPIO_PIN_6, GPIO_PIN_SET) #define NCONFIG_OFF HAL_GPIO_WritePin(GPIOC, GPIO_PIN_6, GPIO_PIN_RESET) #define DCLK_ON HAL_GPIO_WritePin(GPIOI, GPIO_PIN_4, GPIO_PIN_SET) #define DCLK_OFF HAL_GPIO_WritePin(GPIOI, GPIO_PIN_4, GPIO_PIN_RESET) #define DATA0_ON HAL_GPIO_WritePin(GPIOI, GPIO_PIN_8, GPIO_PIN_SET) #define DATA0_OFF HAL_GPIO_WritePin(GPIOI, GPIO_PIN_8, GPIO_PIN_RESET) #define NSTATUS HAL_GPIO_ReadPin(GPIOD, GPIO_PIN_4) #define CONFIG_DONE HAL_GPIO_ReadPin(GPIOC, GPIO_PIN_13)
void MX_GPIO_Init(void) { GPIO_InitTypeDef GPIO_InitStruct = {0}; /* GPIO Ports Clock Enable */ __HAL_RCC_GPIOB_CLK_ENABLE(); __HAL_RCC_GPIOD_CLK_ENABLE(); __HAL_RCC_GPIOC_CLK_ENABLE(); __HAL_RCC_GPIOI_CLK_ENABLE(); __HAL_RCC_GPIOA_CLK_ENABLE(); __HAL_RCC_GPIOH_CLK_ENABLE(); HAL_GPIO_WritePin(GPIOB, SCL_Pin|SDA_Pin, GPIO_PIN_SET); HAL_GPIO_WritePin(GPIOI, DATA0_Pin|DCLK_Pin, GPIO_PIN_SET); HAL_GPIO_WritePin(ARM_LED_GPIO_Port, ARM_LED_Pin, GPIO_PIN_SET); HAL_GPIO_WritePin(nCONFIG_GPIO_Port, nCONFIG_Pin, GPIO_PIN_SET); /*Configure GPIO pins : PBPin PBPin */ GPIO_InitStruct.Pin = SCL_Pin|SDA_Pin; GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; GPIO_InitStruct.Pull = GPIO_PULLUP; GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH; HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); //CONFIG_DONE GPIO_InitStruct.Pin = CONFIG_DONE_Pin; GPIO_InitStruct.Mode = GPIO_MODE_INPUT; GPIO_InitStruct.Pull = GPIO_NOPULL; HAL_GPIO_Init(CONFIG_DONE_GPIO_Port, &GPIO_InitStruct); //DATA0 GPIO_InitStruct.Pin = DATA0_Pin; GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; GPIO_InitStruct.Pull = GPIO_PULLUP; GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; HAL_GPIO_Init(DATA0_GPIO_Port, &GPIO_InitStruct); //DCLK GPIO_InitStruct.Pin = DCLK_Pin; GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; GPIO_InitStruct.Pull = GPIO_PULLUP; GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH; HAL_GPIO_Init(DCLK_GPIO_Port, &GPIO_InitStruct); //nSTATUS GPIO_InitStruct.Pin = nSTATUS_Pin; GPIO_InitStruct.Mode = GPIO_MODE_INPUT; GPIO_InitStruct.Pull = GPIO_NOPULL; HAL_GPIO_Init(nSTATUS_GPIO_Port, &GPIO_InitStruct); /*Configure GPIO pin : PtPin */ GPIO_InitStruct.Pin = ARM_LED_Pin; GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; GPIO_InitStruct.Pull = GPIO_PULLUP; GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH; HAL_GPIO_Init(ARM_LED_GPIO_Port, &GPIO_InitStruct); //nCONFIG GPIO_InitStruct.Pin = nCONFIG_Pin; GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; GPIO_InitStruct.Pull = GPIO_PULLUP; GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH; HAL_GPIO_Init(nCONFIG_GPIO_Port, &GPIO_InitStruct); HAL_I2CEx_EnableFastModePlus(SYSCFG_PMCR_I2C_PB8_FMP); HAL_I2CEx_EnableFastModePlus(SYSCFG_PMCR_I2C_PB7_FMP); }
static void USBH_UserProcess (USBH_HandleTypeDef *phost, uint8_t id) { int i,k; unsigned int counter; unsigned long int ncounter = 0; unsigned char buffer[1024]; FRESULT res; FILINFO finfo; FIL fil; switch(id) {//判断USB状态 case HOST_USER_SELECT_CONFIGURATION: break; case HOST_USER_DISCONNECTION: Appli_state = APPLICATION_DISCONNECT; break; case HOST_USER_CLASS_ACTIVE: Appli_state = APPLICATION_READY; //f_mount,挂载逻辑驱动器 res = f_mount(&fatfs,"0:",1); if(res != RES_OK){ USBH_UsrLog("\r\nf_mount error!"); while(1){ LED_ON; HAL_Delay(500); LED_OFF; HAL_Delay(500); } }else{ USBH_UsrLog("\r\nf_mount successful!"); } usart2.printf("*FPGA Is Updating......\r\n"); NCONFIG_OFF;//进入FPGA PS模式 DCLK_OFF; for(i = 0; i < 5000; i++); if(NSTATUS == 1){//判断FPGA是否已响应配置要求 usart2.printf("\r\n*fpga error!\r\n"); return; } for(i = 0;i < 40;i++); NCONFIG_ON; for(i = 0; i < 40; i++); f_stat ("0:/spi.rbf",&finfo); //获取文件状态 res = f_open(&fil,"0:/spi.rbf",FA_READ);//打开文件 if(res != RES_OK){ usart2.printf("*f_open error!\r\n"); return; } res = f_lseek(&fil,0);//移动文件读/写指针 if(res != RES_OK){ usart2.printf("*f_lseek error!\r\n"); return; } while(ncounter < finfo.fsize) { res = f_read(&fil,buffer,1024,&counter);//读取文件 if(res != RES_OK){ usart2.printf("\r\n*f_read error!\r\n"); return; } for(k = 0; k < counter; k++) { for(i = 0; i < 8; i++) { if(buffer[k]&0x01)DATA0_ON; else DATA0_OFF; DCLK_ON; buffer[k] >>= 1; DCLK_OFF; } ncounter++; } } if(CONFIG_DONE == 0){ usart2.printf("\r\n*config error!\r\n"); return; } for(i = 0; i < 40; i++) { DCLK_ON; for(i = 0; i < 800; i++); DCLK_OFF; for(i = 0; i < 800; i++); } usart2.printf("*Update Completed!\r\n"); break; case HOST_USER_CONNECTION: Appli_state = APPLICATION_START; break; default: break; } }