银杏科技有限公司旗下技术文档发布平台 | |||
技术支持电话 | 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.配置串口。 在NVIC Settings一栏使能接收中断。 引脚配置 8.配置USB_OTG_HS。 9.配置USB_HOST。 10.配置FATFS。 11.时钟源设置,选择外部高速时钟源,配置为最大主频。 12.工程文件的设置, 这里就是工程的各种配置 我们只用到有限几个,其他的默认即可 IDE我们使用的是 MDK V5.27。 13.点击Code Generator,进行进一步配置。
1.USB简介
2.OTG主要特性
int main(void) { 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_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 iCore4TX.\r\n"); while (1) { MX_USB_HOST_Process(); } }
void MX_USB_HOST_Init(void) { /* 初始化主机库,添加支持的类并启动该库 */ if (USBH_Init(&hUsbHostHS, USBH_UserProcess, HOST_HS) != USBH_OK) { Error_Handler(); } if (USBH_RegisterClass(&hUsbHostHS, USBH_MSC_CLASS) != USBH_OK) { Error_Handler(); } if (USBH_Start(&hUsbHostHS) != USBH_OK) { Error_Handler(); } }
static void USBH_UserProcess (USBH_HandleTypeDef *phost, uint8_t id) { int i,j; static FRESULT res; unsigned char write_buffer[512]; unsigned char read_buffer[512]; unsigned int counter; switch(id) { 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!"); } //f_open for(i = 0; i < 512 ; i ++)write_buffer[i] = i % 256; res = f_open(&file,"0:/test.txt",FA_READ | FA_WRITE | FA_OPEN_ALWAYS); //打开驱动器0上的源文件 if(res != RES_OK){ USBH_UsrLog("f_open error!"); while(1){ LED_ON; HAL_Delay(500); LED_OFF; HAL_Delay(500); } }else{ USBH_UsrLog("f_open successful!"); } //f_lseek res = f_lseek(&file,0); if(res != RES_OK){ USBH_UsrLog("f_lseek error!"); while(1){ LED_ON; HAL_Delay(500); LED_OFF; HAL_Delay(500); } }else{ USBH_UsrLog("f_lseek successful!"); } //f_write res = f_write(&file,write_buffer,512,&counter); if(res != RES_OK || counter != 512){ USBH_UsrLog("f_write error!"); while(1){ LED_ON; HAL_Delay(500); LED_OFF; HAL_Delay(500); } }else{ USBH_UsrLog("f_write successful!"); } //f_lseek res = f_lseek(&file,0); if(res != RES_OK){ USBH_UsrLog("f_lseek error!"); while(1){ LED_ON; HAL_Delay(500); LED_OFF; HAL_Delay(500); } }else{ USBH_UsrLog("f_lseek successful!"); } //f_read res = f_read(&file,read_buffer,512,&counter); if(res != RES_OK || counter != 512){ USBH_UsrLog("f_read error!"); while(1){ LED_ON; HAL_Delay(500); LED_OFF; HAL_Delay(500); } }else{ USBH_UsrLog("f_read successful!"); } f_close(&file); USBH_UsrLog("read data:"); for(i = 0;i < 32;i++){ for(j = 0; j < 16; j ++) usart2.printf("%02X ",read_buffer[i*16+j]); usart2.printf("\r\n"); } break; case HOST_USER_CONNECTION: Appli_state = APPLICATION_START; break; default: break; } }