/** * @brief Initialize the host driver * @param hhcd : HCD handle * @retval HAL state */ HAL_StatusTypeDef HAL_HCD_Init(HCD_HandleTypeDef *hhcd) { /* Check the HCD handle allocation */ if(hhcd == NULL) { return HAL_ERROR; } /* Check the parameters */ assert_param(IS_HCD_ALL_INSTANCE(hhcd->Instance)); hhcd->State = HCD_BUSY; /* Init the low level hardware : GPIO, CLOCK, NVIC... */ HAL_HCD_MspInit(hhcd); /* Disable the Interrupts */ __HAL_HCD_DISABLE(hhcd); /*Init the Core (common init.) */ USB_CoreInit(hhcd->Instance, hhcd->Init); /* Force Host Mode*/ USB_SetCurrentMode(hhcd->Instance , USB_OTG_HOST_MODE); /* Init Host */ USB_HostInit(hhcd->Instance, hhcd->Init); hhcd->State= HCD_READY; return HAL_OK; }
static void USB_HostApplicationInit(void) { usb_status_t status = kStatus_USB_Success; IRQn_Type usbIrq; #if ((defined USB_HOST_CONFIG_KHCI) && (USB_HOST_CONFIG_KHCI)) IRQn_Type usbFsIrqs[] = USB_IRQS; usbIrq = usbFsIrqs[CONTROLLER_ID - kUSB_ControllerKhci0]; CLOCK_EnableUsbfs0Clock(kCLOCK_UsbSrcPll0, CLOCK_GetFreq(kCLOCK_PllFllSelClk)); #endif /* USB_HOST_CONFIG_KHCI */ #if ((defined USB_HOST_CONFIG_EHCI) && (USB_HOST_CONFIG_EHCI)) IRQn_Type usbHsIrqs[] = USBHS_IRQS; usbIrq = usbHsIrqs[CONTROLLER_ID - kUSB_ControllerEhci0]; CLOCK_EnableUsbhs0Clock(kCLOCK_UsbSrcPll0, CLOCK_GetFreq(kCLOCK_PllFllSelClk)); USB_EhciPhyInit(CONTROLLER_ID, BOARD_XTAL0_CLK_HZ); #endif /* USB_HOST_CONFIG_EHCI */ #if ((defined FSL_FEATURE_SOC_MPU_COUNT) && (FSL_FEATURE_SOC_MPU_COUNT)) MPU_Enable(MPU, 0); #endif /* FSL_FEATURE_SOC_MPU_COUNT */ status = USB_HostInit(CONTROLLER_ID, &g_HostHandle, USB_HostEvent); if (status != kStatus_USB_Success) { usb_echo("host init error\r\n"); return; } NVIC_SetPriority(usbIrq, USB_HOST_INTERRUPT_PRIORITY); NVIC_EnableIRQ(usbIrq); usb_echo("host init done\r\n"); }
/*! * @brief app initialization. */ void APP_init(void) { usb_status_t status = kStatus_USB_Success; IRQn_Type usb_irq; usb_uartConfiguration uartConfiguration; g_xfer.buffer = (uint8_t *)&usbRecvUart[0]; g_xfer.size = USB_HOST_CDC_UART_RX_MAX_LEN; USB_UartGetDefaultConfiguratoion(&uartConfiguration); uartConfiguration.baudRate_Bps = BOARD_DEBUG_UART_BAUDRATE; uartConfiguration.enableTx = true; uartConfiguration.enableRx = true; USB_UartInit((USB_UartType *)BOARD_DEBUG_UART_BASEADDR, &uartConfiguration, CLOCK_GetFreq(BOARD_DEBUG_UART_CLKSRC)); USB_UartCreateHandle((USB_UartType *)BOARD_DEBUG_UART_BASEADDR, &g_UartHandle, UART_UserCallback, NULL); USB_UartReceiveDataIRQ((USB_UartType *)BOARD_DEBUG_UART_BASEADDR, &g_UartHandle, &g_xfer, NULL); g_AttachFlag = 0; USB_HostCdcInitBuffer(); #if ((defined USB_HOST_CONFIG_KHCI) && (USB_HOST_CONFIG_KHCI)) IRQn_Type usb_fs_irqs[] = USB_IRQS; usb_irq = usb_fs_irqs[CONTROLLER_ID - kUSB_ControllerKhci0]; CLOCK_EnableUsbfs0Clock(kCLOCK_UsbSrcPll0, CLOCK_GetFreq(kCLOCK_PllFllSelClk)); #endif #if ((defined USB_HOST_CONFIG_EHCI) && (USB_HOST_CONFIG_EHCI)) IRQn_Type usb_hs_irqs[] = USBHS_IRQS; usb_irq = usb_hs_irqs[CONTROLLER_ID - kUSB_ControllerEhci0]; CLOCK_EnableUsbhs0Clock(kCLOCK_UsbSrcPll0, CLOCK_GetFreq(kCLOCK_PllFllSelClk)); USB_EhciPhyInit(CONTROLLER_ID, BOARD_XTAL0_CLK_HZ); #endif #if ((defined FSL_FEATURE_SOC_MPU_COUNT) && (FSL_FEATURE_SOC_MPU_COUNT)) MPU_Enable(MPU, 0); #endif /* FSL_FEATURE_SOC_MPU_COUNT */ status = USB_HostInit(CONTROLLER_ID, &g_hostHandle, USB_HostEvent); if (status != kStatus_USB_Success) { usb_echo("host init error\r\n"); return; } NVIC_SetPriority(usb_irq, USB_HOST_INTERRUPT_PRIORITY); NVIC_EnableIRQ(usb_irq); usb_echo("host init done\r\n"); usb_echo("This example requires that the CDC device uses Hardware flow\r\n"); usb_echo( "if the device does't support it, please set USB_HOST_UART_SUPPORT_HW_FLOW to zero and rebuild this " "project\r\n"); usb_echo("Type strings, then the string\r\n"); usb_echo("will be echoed back from the device\r\n"); }