USB host can't detect the disconnection on imx6sx m4

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

USB host can't detect the disconnection on imx6sx m4

Jump to solution
1,644 Views
johnesmith
Contributor II

Hi, I am working on imx6sx m4 USB host function to try to connect with a CDC class device. By now I can see my project can attach the device successfully. But I didn't see the port change interrupt occur when I plug-out the device.

Below is what I've done to initialize the USB PHY.

/*Regulator*/

void usb_regulator_init(void)
{
uint32_t val;
/* Enable VBUS by driving GPIO1_IO12 to high. */
IOMUXC_SW_MUX_CTL_PAD_GPIO1_IO12 = IOMUXC_SW_MUX_CTL_PAD_GPIO1_IO12_MUX_MODE(5);
GPIO1->GDIR |= 0x00001000;
GPIO1->DR |= 0x00001000;
/* Set voltage to 3.2V */
val = PMU_REG_3P0_REG(PMU);
val &= ~PMU_REG_3P0_OUTPUT_TRG_MASK;
val |= PMU_REG_3P0_OUTPUT_TRG(0x17);
PMU_REG_3P0_REG(PMU) = val;
/* Enable regulator. */
val = PMU_REG_3P0_REG(PMU);
val |= PMU_REG_3P0_ENABLE_LINREG_MASK;
PMU_REG_3P0_REG(PMU) = val;
}
/*Clock*/
void usb_clock_init(void)
{
/* Enable uog2 clock, pll3 was generated by cortex A9 */
CCM_ControlGate(CCM, ccmCcgrGateUsboh3Clk, ccmClockNeededAll);
/* Enable PLL. */
CCM_ANALOG_PLL_USB2_SET = CCM_ANALOG_PLL_USB2_ENABLE_MASK;
/* Power up the PLL. */
CCM_ANALOG_PLL_USB2_SET = CCM_ANALOG_PLL_USB2_POWER_MASK;
/* Wait for the lock assert. */
while (0 == (CCM_ANALOG_PLL_USB2 & CCM_ANALOG_PLL_USB2_LOCK_MASK))
;
/* Clear bypass bit. */
CCM_ANALOG_PLL_USB2_CLR = CCM_ANALOG_PLL_USB2_BYPASS_MASK;
/* Enable USB clock. */
CCM_ANALOG_PLL_USB2_SET = CCM_ANALOG_PLL_USB2_EN_USB_CLKS_MASK;
}
/*PHY*/
void usb_phy_init(void)
{
uint32_t val;
/* Clear clock gate. */
USBPHY_CTRL_SET_REG(USBPHY2) = USBPHY_CTRL_SET_SFTRST_MASK;
USBPHY_CTRL_CLR_REG(USBPHY2) = USBPHY_CTRL_CLR_CLKGATE_MASK;
USBPHY_CTRL_CLR_REG(USBPHY2) = USBPHY_CTRL_CLR_SFTRST_MASK;
/* Clear power down. */
USBPHY_PWD_CLR_REG(USBPHY2) = 0xFFFFFFFF;
/* Set control bits. */
USBPHY_CTRL_SET_REG(USBPHY2) = USBPHY_CTRL_SET_ENUTMILEVEL2_MASK | USBPHY_CTRL_SET_ENUTMILEVEL3_MASK |
USBPHY_CTRL_SET_ENAUTOCLR_CLKGATE_MASK | USBPHY_CTRL_SET_ENAUTOCLR_PHY_PWD_MASK;
val = USBPHY_TX_REG(USBPHY2);
val &= ~USBPHY_TX_SET_D_CAL_MASK;
USBPHY_TX_CLR_REG(USBPHY2) = USBPHY_TX_SET_D_CAL_MASK;
USBPHY_TX_SET_REG(USBPHY2) = (val | 0x5);
}
BTW, I've enabled the port change interrupt in INTR as below, and I'm sure it works well since it can enumerate and attach the device successfully.
/* enable interrupt */
ehciInstance->ehciIpBase->UOG1_USBINTR |= (0x1000037);
But it didn't run into port change handler when I plug-out the device. Anything else I've missing to make the USB host detect the disconnection?
0 Kudos
1 Solution
1,185 Views
CarlosCasillas
NXP Employee
NXP Employee

Hi,

You could take a look to “ENHOSTDISCONDETECT bit” and/or “Host disconnect detector: DISCONADJ” of application note AN4589 “Configuring USB on i.MX 6 Series Processors”, available at the following link:

http://www.nxp.com/assets/documents/data/en/application-notes/AN4589.pdf

Hope this will be useful for you.
Best regards!
/Carlos
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

View solution in original post

6 Replies
1,185 Views
johnesmith
Contributor II

Finally I realized that the “ENHOSTDISCONDETECT bit” should be cleared in case of SUSPEND happened as mentioned in the application note. After clear this bit, the device can work well the next time when plugging in.

 

usb_disconnection_detect.PNG 

1,185 Views
johnesmith
Contributor II

Is there any reference code for the USB PHY initialization?

0 Kudos
1,185 Views
johnesmith
Contributor II

Anyone can help on this issue, or where can I get the reference code to initialize the USB host on imx6sx m4 properly?

0 Kudos
1,186 Views
CarlosCasillas
NXP Employee
NXP Employee

Hi,

You could take a look to “ENHOSTDISCONDETECT bit” and/or “Host disconnect detector: DISCONADJ” of application note AN4589 “Configuring USB on i.MX 6 Series Processors”, available at the following link:

http://www.nxp.com/assets/documents/data/en/application-notes/AN4589.pdf

Hope this will be useful for you.
Best regards!
/Carlos
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

1,185 Views
johnesmith
Contributor II

Hi Carlos,

Thanks for your help!

The host can detect the disconnection event with the USBPHY_CTRL_ENHOSTDISCONDETECT_MASK bit setting to 1 in USB_PHY_CTRL. There are port change interrupts whenever I plug out or plug in the device. But the host can NOT finish the enumeration when I re-plugin the device. 

I found some differences for USB_nPORTSC1 register among plug in, plug out and re-plugin. Below is the value of USB_nPORTSC1 which is logging from the beginning of USB_HostEhciPortChange().

1) Plug in. This is the first time to plug in the device. It can get enumerated successfully and work as expected.

USB_nPORTSC1 : 0x10001803

USB_nPORTSC1 : 0x1c001002
USB_nPORTSC1 : 0x18001205

2) Plug out. The port change interrupt occurs. 

USB_nPORTSC1 : 0x1c00100a
USB_nPORTSC1 : 0x1c001008

3) Re-plugin. This time the value of USB_nPORTSC1 differs from the one when plugging in in step 1. And the host failed to finish the enumeration. 

USB_nPORTSC1: 0x1000180b
USB_nPORTSC1: 0x1c00100a
USB_nPORTSC1: 0x1000180b

Is there anything I am missing when re-plugin the device?  Any help would be appreciated:)

0 Kudos
1,185 Views
johnesmith
Contributor II

Is there any clue on the value of USB_nPORTSC1?  Anyone can help me on this issue? 

0 Kudos