I already could test your code and effectively, it works doing modifications that I mentioned before.
MCG_C1 |= MCG_C1_IRCLKEN_MASK; /* 32kHz IRC enable */
OSC_CR |= OSC_CR_ERCLKEN_MASK; /* External reference clock enable */
SIM_SOPT2 |= SIM_SOPT2_USBREGEN_MASK; /* Enable USB PHY PLL regulator */
SIM_SCGC3 |= SIM_SCGC3_USBHSPHY_MASK; /* Open USB PHY clock gate */
SIM_USBPHYCTL = SIM_USBPHYCTL_USB3VOUTTRG(6); /* trim the USB regulator output to be 3.13V */
SIM_USBPHYCTL |= SIM_USBPHYCTL_USBVREGSEL_MASK; /* Selects VREG_IN1 */
USBPHY_CTRL &= ~USBPHY_CTRL_SFTRST_MASK; /* Release PHY from reset */
USBPHY_CTRL &= ~USBPHY_CTRL_CLKGATE_MASK; /* Gate UTMI Clocks */
/* Enables TRIM OVERRIDE */
USBPHY_TRIM_OVERRIDE_EN |= USBPHY_TRIM_OVERRIDE_EN_CLR_TRIM_DIV_SEL_OVERRIDE_MASK;
/* Power PHY's PLL */
USBPHY_PLL_SIC |= USBPHY_PLL_SIC_CLR_PLL_POWER_MASK;
/* In TWR-K65F180M board, Crystal is 16 MHz */
int crystal_val = 16000000;
/* Select appropiate value for PLL_DIV_SEL */
if(crystal_val == 24000000)
USBPHY_PLL_SIC &= ~USBPHY_PLL_SIC_PLL_DIV_SEL_MASK;
else if(crystal_val == 16000000)
USBPHY_PLL_SIC |= USBPHY_PLL_SIC_PLL_DIV_SEL(1);
else if(crystal_val == 12000000)
USBPHY_PLL_SIC |= USBPHY_PLL_SIC_PLL_DIV_SEL(2);
/* Wait until PLL is locked */
while (!(USBPHY_PLL_SIC & USBPHY_PLL_SIC_PLL_LOCK_MASK));
/* if program reaches this point, PLL was locked successfully */
i++;
In my hardware settings, I connected VBUS from USB connector to VREG_IN1. I used TWR-K65F180M so you could check its schematic for any doubt about hardware connections.