Frank
There is nothing CDC specific so you only need to modify the initialisation.
I have copied "all" code - it is only a few lines - that is needed to configure the K22 chip and its USB to run everything directly from IRC48M below so that you can immediately use it if you prefer not to wait.
Regards
Mark
.. clock initialisation
MCG_C2 = MCG_C2_EREFS; // request oscillator
OSC0_CR |= (OSC_CR_ERCLKEN | OSC_CR_EREFSTEN); // enable the external reference clock and keep it enabled in stop mode
MCG_C7 = MCG_C7_OSCSEL_IRC48MCLK; // route the IRC48M clock to the external reference clock input (this enables IRC48M)
SIM_CLKDIV1 = (((SYSTEM_CLOCK_DIVIDE - 1) << 28) | ((BUS_CLOCK_DIVIDE - 1) << 24) | ((FLEX_CLOCK_DIVIDE - 1) << 20) | ((FLASH_CLOCK_DIVIDE - 1) << 16)); // prepare bus clock divides
MCG_C1 = (MCG_C1_IREFS | MCG_C1_CLKS_EXTERN_CLK); // switch IRC48M reference to MCGOUTCLK
while ((MCG_S & MCG_S_CLKST_MASK) != MCG_S_CLKST_EXTERN_CLK) { // wait until the new source is valid (move to FBI using IRC48M external source is complete)
}
MCG_C2 |= MCG_C2_LP; // set bypass to disable FLL and complete move to BLPE (in which PLL is also always disabled)
.. Now the CPU is operating at 48MHz (when SYSTEM_CLOCK_DIVIDE is 1) and its bus and flash clocks are at the requested speeds
.. USB clock mode initialisation (before powering USB)
SIM_SOPT2 |= (SIM_SOPT2_USBSRC | SIM_SOPT2_PLLFLLSEL_IRC48M); // set the source to IRC48M
SIM_CLKDIV2 = SIM_CLKDIV2_USBDIV_1; // no divide when IRC48M is used
... now power up the USB controller and reset it
.. now enable clock recovery
USB_CLK_RECOVER_IRC_EN = USB_CLK_RECOVER_IRC_EN_IRC_EN; // enable 48MHz IRC clock and clock recovery (this may have been disabled by the USB reset command)
USB_CLK_RECOVER_CTRL = USB_CLK_RECOVER_CTRL_CLOCK_RECOVER_EN;
.. start working with USB device