We use external 16MHz crystal oscillator for LPC11U68JBD48E clock:
unsigned int j;
SystemCoreClockUpdate();
Chip_Clock_EnablePeriphClock(SYSCTL_CLOCK_IOCON);
// start SYSOSC
Chip_IOCON_PinMuxSet(LPC_IOCON, 2, 0, (IOCON_FUNC1 | IOCON_MODE_INACT)); // PIO2_0 = XTALIN
Chip_IOCON_PinMuxSet(LPC_IOCON, 2, 1, (IOCON_FUNC1 | IOCON_MODE_INACT)); // PIO2_1 = XTALOUT
Chip_SYSCTL_PowerUp(SYSCTL_POWERDOWN_SYSOSC_PD);
Chip_Clock_SetPLLBypass(false, false);
for (j = 0; j < 0x400; ++j); // 500us delay is needed after SYSOSC is powered up
// MAINCLK = 64MHz, from PLL
Chip_Clock_SetMainClockSource(SYSCTL_MAINCLKSRC_IRC);
Chip_SYSCTL_PowerDown(SYSCTL_POWERDOWN_SYSPLL_PD);
Chip_Clock_SetSystemPLLSource(SYSCTL_PLLCLKSRC_MAINOSC);
Chip_Clock_SetupSystemPLL(3, 1); // FCLKIN = 16, FCLKOUT = 64, FCCO = 256MHz
Chip_SYSCTL_PowerUp(SYSCTL_POWERDOWN_SYSPLL_PD);
while (!Chip_Clock_IsSystemPLLLocked());
Chip_Clock_SetSysClockDiv(2); // system clock at 32Mhz
Chip_Clock_SetMainClockSource(SYSCTL_MAINCLKSRC_PLLOUT);
SystemCoreClockUpdate();
// so far so good, turning off IRC:
Chip_SYSCTL_PowerDown(SYSCTL_POWERDOWN_IRC_PD);
Chip_SYSCTL_PowerDown(SYSCTL_POWERDOWN_IRCOUT_PD);
// now lets try set up USB clock:
Chip_SYSCTL_PowerDown(SYSCTL_POWERDOWN_USBPLL_PD);
Chip_Clock_SetUSBPLLSource(SYSCTL_USBPLLCLKSRC_MAINOSC);
Chip_Clock_SetupUSBPLL(2, 1); // FCLKIN = 16, FCLKOUT = 48, FCCO = 192MHz
Chip_SYSCTL_PowerUp(SYSCTL_POWERDOWN_USBPLL_PD);
while (!Chip_Clock_IsUSBPLLLocked()); // hangs here indefinitely
// and this code is not reached ...
Chip_Clock_SetUSBClockSource(SYSCTL_USBCLKSRC_PLLOUT, 1);
Chip_Clock_EnablePeriphClock(SYSCTL_CLOCK_USB);
Chip_Clock_EnablePeriphClock(SYSCTL_CLOCK_USBRAM);
Chip_SYSCTL_PowerUp(SYSCTL_POWERDOWN_USBPAD_PD);
So, could USB PLL be used when IRC is turned off?
Solved! Go to Solution.
Hi, Alexei,
It appears that you do not set up the USB PLL Clock source register, pls check.
Hope it can help you
BR
XiangJun Rong
Hi, Alexei,
It appears that you do not set up the USB PLL Clock source register, pls check.
Hope it can help you
BR
XiangJun Rong
Hi, xiangjun_rong
Thanks, it appears I missed the line in manual: When switching clock sources, both clocks must be running.
When IRC is turned off after USB PLL setup, everything runs ok.