Changing USB ports at run time.

cancel
Showing results for 
Search instead for 
Did you mean: 

Changing USB ports at run time.

183 Views
Contributor IV

I'm using MCUXpresso SDK 2.6.2 and USB stack on the MIMXRT1062. I want to chance the USB port I'm using at run time. So I undo the initialization done by the host_cdc_bm example, in reverse order; that is, I disable the IRQ, call USB_HostDeinit(), and then CLOCK_DisableUsbhs0PhyPllClock() or CLOCK_DisableUsbhs1PhyPllClock(). But there is no call to disable the enable done by CLOCK_EnableUsbhs0Clock() or CLOCK_EnableUsbhs1Clock(), and when I subsequently try to enable the other USB HS peripheral, I get a hard fault.

How do I properly tear down one USB port in order to bring up the other?

Labels (1)
0 Kudos
4 Replies

31 Views
NXP TechSupport
NXP TechSupport

Hi Jeffery,

 

First of all, I just want to let you know that you are not using our latest SDK version. You can download latest version from here: https://mcuxpresso.nxp.com/en/select

 

Regarding your question, I have created a quick example to demonstrate how you can implement this. I am using MIMXRT1060-EVK and SDK 2.7.0.

 

The example starts using kUSB_ControllerEhci0 but changes to kUSB_ControllerEhci1 is you press SW8. Please make sure you detach the device before the switch.

 

I hope his helps!

 

Best regards,

Felipe

-------------------------------------------------------------------------------
Note:
- If this post answers your question, please click the "Mark Correct" button. Thank you!

- We are following threads for 7 weeks after the last post, later replies are ignored
Please open a new thread and refer to the closed one, if you have a related question at a later point in time.
-------------------------------------------------------------------------------

0 Kudos

31 Views
Contributor IV

Thanks, Felipe!

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 );
}

0 Kudos

31 Views
NXP TechSupport
NXP TechSupport

Hi Jeffery,

 

Could you please try the example only first? Maybe there is an issue with your application. I double checked the project that I attached and it is working correctly on my side. I used SDK 2.7.0 and MCUXpresso 11.1.1 to test it.

 

Best regards,

Felipe

0 Kudos

31 Views
Contributor IV

Once we’re allowed back into the building I can do that. At this point, I’m assuming the problem is definitely in my code; I’m just trying to figure out where to look.

Jeff Thompson | Senior Electrical Engineer-Firmware

+1 704 752 6513 x1394

www.invue.com

0 Kudos