When SDK 2.7.0 came out, we were already too late in the development cycle to consider changing SDKs due to risk aversion and the amount of testing already done.
I made some changes to the function that handles the port change in order to accommodate our application, but only the error checking and semaphore protection get called before the original code, which hangs in the CLOCK_EnableUsbhs1Clock() when I call .APP_changeUsbPort() with argument kUSB_ControllerEhci1, and kUSB_ControllerEhci0 running.
usb_controller_index_t g_usbControllerIndex = kUSB_ControllerEhci0;
void APP_changeUsbPort( usb_controller_index_t newUsbControllerIndex )
{
USB_HostDeinit(g_hostHandle);
usb_phy_config_struct_t phyConfig = {
BOARD_USB_PHY_D_CAL,
BOARD_USB_PHY_TXCAL45DP,
BOARD_USB_PHY_TXCAL45DM,
};
if( newUsbControllerIndex == g_usbControllerIndex )
{
return;
}
else
{
g_usbControllerIndex = newUsbControllerIndex;
}
xSemaphoreTake( usbSemaphore, portMAX_DELAY );
if ( kUSB_ControllerEhci1 == newUsbControllerIndex )
{
CLOCK_EnableUsbhs1PhyPllClock(kCLOCK_Usbphy480M, 480000000U);
CLOCK_EnableUsbhs1Clock(kCLOCK_Usb480M, 480000000U);
USB_EhciPhyInit(kUSB_ControllerEhci1, BOARD_XTAL0_CLK_HZ, &phyConfig);
status_t status = USB_HostInit(kUSB_ControllerEhci1, &g_hostHandle, USB_HostEvent);
if (status != kStatus_USB_Success)
{
PRINTF( "%s host init 1 error\r\n", __FUNCTION__ );
}
/* Install isr, set priority, and enable IRQ. */
#if defined(__GIC_PRIO_BITS)
GIC_SetPriority((IRQn_Type)USB_OTG2_IRQn, USB_HOST_INTERRUPT_PRIORITY);
#else
NVIC_SetPriority(USB_OTG2_IRQn, USB_HOST_INTERRUPT_PRIORITY);
#endif
EnableIRQ(USB_OTG2_IRQn);
}
else
{
CLOCK_EnableUsbhs0PhyPllClock(kCLOCK_Usbphy480M, 480000000U);
CLOCK_EnableUsbhs0Clock(kCLOCK_Usb480M, 480000000U);
USB_EhciPhyInit(kUSB_ControllerEhci0, BOARD_XTAL0_CLK_HZ, &phyConfig);
status_t status = USB_HostInit(kUSB_ControllerEhci0, &g_hostHandle, USB_HostEvent);
if (status != kStatus_USB_Success)
{
PRINTF( "%s host init 0 error\r\n", __FUNCTION__ );
}
/* Install isr, set priority, and enable IRQ. */
#if defined(__GIC_PRIO_BITS)
GIC_SetPriority((IRQn_Type)USB_OTG1_IRQn, USB_HOST_INTERRUPT_PRIORITY);
#else
NVIC_SetPriority(USB_OTG1_IRQn, USB_HOST_INTERRUPT_PRIORITY);
#endif
EnableIRQ(USB_OTG1_IRQn);
}
// application initialization
USB_initialize();
xSemaphoreGive( usbSemaphore );
}