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 Application initialization function. * * This function initializes the application. * * @return None. */ void APPInit(void) { uint8_t irqNo; #if defined(USB_DEVICE_CONFIG_EHCI) && (USB_DEVICE_CONFIG_EHCI > 0) uint8_t ehciIrq[] = USBHS_IRQS; irqNo = ehciIrq[CONTROLLER_ID - kUSB_ControllerEhci0]; CLOCK_EnableUsbhs0Clock(kCLOCK_UsbSrcPll0, CLOCK_GetFreq(kCLOCK_PllFllSelClk)); USB_EhciPhyInit(CONTROLLER_ID, BOARD_XTAL0_CLK_HZ); #endif #if defined(USB_DEVICE_CONFIG_KHCI) && (USB_DEVICE_CONFIG_KHCI > 0) uint8_t khciIrq[] = USB_IRQS; irqNo = khciIrq[CONTROLLER_ID - kUSB_ControllerKhci0]; SystemCoreClockUpdate(); #if ((defined FSL_FEATURE_USB_KHCI_IRC48M_MODULE_CLOCK_ENABLED) && (FSL_FEATURE_USB_KHCI_IRC48M_MODULE_CLOCK_ENABLED)) CLOCK_EnableUsbfs0Clock(kCLOCK_UsbSrcIrc48M, 48000000U); #else CLOCK_EnableUsbfs0Clock(kCLOCK_UsbSrcPll0, CLOCK_GetFreq(kCLOCK_PllFllSelClk)); #endif /* FSL_FEATURE_USB_KHCI_IRC48M_MODULE_CLOCK_ENABLED */ #endif #if (defined(FSL_FEATURE_SOC_MPU_COUNT) && (FSL_FEATURE_SOC_MPU_COUNT > 0U)) MPU_Enable(MPU, 0); #endif /* FSL_FEATURE_SOC_MPU_COUNT */ /* * If the SOC has USB KHCI dedicated RAM, the RAM memory needs to be clear after * the KHCI clock is enabled. When the demo uses USB EHCI IP, the USB KHCI dedicated * RAM can not be used and the memory can't be accessed. */ #if (defined(FSL_FEATURE_USB_KHCI_USB_RAM) && (FSL_FEATURE_USB_KHCI_USB_RAM > 0U)) #if (defined(FSL_FEATURE_USB_KHCI_USB_RAM_BASE_ADDRESS) && (FSL_FEATURE_USB_KHCI_USB_RAM_BASE_ADDRESS > 0U)) for (int i = 0; i < FSL_FEATURE_USB_KHCI_USB_RAM; i++) { ((uint8_t *)FSL_FEATURE_USB_KHCI_USB_RAM_BASE_ADDRESS)[i] = 0x00U; } #endif /* FSL_FEATURE_USB_KHCI_USB_RAM_BASE_ADDRESS */ #endif /* FSL_FEATURE_USB_KHCI_USB_RAM */ s_cdcVcom.speed = USB_SPEED_FULL; s_cdcVcom.attach = 0; s_cdcVcom.deviceHandle = NULL; if (kStatus_USB_Success != USB_DeviceInit(CONTROLLER_ID, USB_DeviceCallback, &s_cdcVcom.deviceHandle)) { usb_echo("USB device vcom failed\r\n"); return; } else { usb_echo("USB device CDC vcom demo\r\n"); } NVIC_SetPriority((IRQn_Type)irqNo, USB_DEVICE_INTERRUPT_PRIORITY); NVIC_EnableIRQ((IRQn_Type)irqNo); USB_DeviceRun(s_cdcVcom.deviceHandle); }
/*! * @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"); }
/* Application initialization */ static void USB_DeviceApplicationInit(void) { uint8_t irqNumber; #if defined(USB_DEVICE_CONFIG_EHCI) && (USB_DEVICE_CONFIG_EHCI > 0U) uint8_t usbDeviceEhciIrq[] = USBHS_IRQS; irqNumber = usbDeviceEhciIrq[CONTROLLER_ID - kUSB_ControllerEhci0]; CLOCK_EnableUsbhs0Clock(kCLOCK_UsbSrcPll0, CLOCK_GetFreq(kCLOCK_PllFllSelClk)); USB_EhciPhyInit(CONTROLLER_ID, BOARD_XTAL0_CLK_HZ); #endif #if defined(USB_DEVICE_CONFIG_KHCI) && (USB_DEVICE_CONFIG_KHCI > 0U) uint8_t usbDeviceKhciIrq[] = USB_IRQS; irqNumber = usbDeviceKhciIrq[CONTROLLER_ID - kUSB_ControllerKhci0]; SystemCoreClockUpdate(); #if ((defined FSL_FEATURE_USB_KHCI_IRC48M_MODULE_CLOCK_ENABLED) && (FSL_FEATURE_USB_KHCI_IRC48M_MODULE_CLOCK_ENABLED)) CLOCK_EnableUsbfs0Clock(kCLOCK_UsbSrcIrc48M, 48000000U); #else CLOCK_EnableUsbfs0Clock(kCLOCK_UsbSrcPll0, CLOCK_GetFreq(kCLOCK_PllFllSelClk)); #endif /* FSL_FEATURE_USB_KHCI_IRC48M_MODULE_CLOCK_ENABLED */ #endif #if (defined(FSL_FEATURE_SOC_MPU_COUNT) && (FSL_FEATURE_SOC_MPU_COUNT > 0U)) MPU_Enable(MPU, 0); #endif /* FSL_FEATURE_SOC_MPU_COUNT */ /* * If the SOC has USB KHCI dedicated RAM, the RAM memory needs to be clear after * the KHCI clock is enabled. When the demo uses USB EHCI IP, the USB KHCI dedicated * RAM can not be used and the memory can't be accessed. */ #if (defined(FSL_FEATURE_USB_KHCI_USB_RAM) && (FSL_FEATURE_USB_KHCI_USB_RAM > 0U)) #if (defined(FSL_FEATURE_USB_KHCI_USB_RAM_BASE_ADDRESS) && (FSL_FEATURE_USB_KHCI_USB_RAM_BASE_ADDRESS > 0U)) for (int i = 0; i < FSL_FEATURE_USB_KHCI_USB_RAM; i++) { ((uint8_t *)FSL_FEATURE_USB_KHCI_USB_RAM_BASE_ADDRESS)[i] = 0x00U; } #endif /* FSL_FEATURE_USB_KHCI_USB_RAM_BASE_ADDRESS */ #endif /* FSL_FEATURE_USB_KHCI_USB_RAM */ /* Set composite device default state */ g_UsbDeviceComposite.speed = USB_SPEED_FULL; g_UsbDeviceComposite.attach = 0U; g_UsbDeviceComposite.deviceHandle = NULL; /* Initialize the usb stack and class drivers */ if (kStatus_USB_Success != USB_DeviceInit(CONTROLLER_ID, USB_DeviceCallback, &g_UsbDeviceComposite.deviceHandle)) { usb_echo("USB device composite demo init failed\r\n"); return; } else { usb_echo("USB device composite demo\r\n"); } USB_DeviceHidKeyboardInit(&g_UsbDeviceComposite); USB_DeviceHidMouseInit(&g_UsbDeviceComposite); /* Install isr, set priority, and enable IRQ. */ NVIC_SetPriority((IRQn_Type)irqNumber, USB_DEVICE_INTERRUPT_PRIORITY); NVIC_EnableIRQ((IRQn_Type)irqNumber); /* Start USB device composite */ USB_DeviceRun(g_UsbDeviceComposite.deviceHandle); }