AnsweredAssumed Answered

USB host can't detect the disconnection on imx6sx m4

Question asked by johne smith on Mar 5, 2017
Latest reply on Mar 24, 2017 by johne smith

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?

Outcomes