The demo projects is made with Processor Expert components so it can be easily copied or ported to another board:
I have created a demo application which echoes the entered text back on the console, with incrementing a counter:
FSL_USB_Stack with FSL_USB_CDC_Device
With just two additional Processor Expert components, it is possible to add USB CDC functionality to an existing projects in just a few minutes. See “USB Component Splitted and Updated” for architectural information. The component has now added a Kinetis K20D50 option:
💡 The FSL_USB_CDC_Device component features now an optional timeout feature. With this, it is easer to use the component in a bare-metal environment. It is using the extra ‘Timeout’ component which implements a timer based timeout to avoid stalling of the stack.
USB Clock Configuration
The most difficult part is the clock configuration. The USB block needs a 48 MHz clock to sample the 24 MHz USB signal. In the CPU component properties, I configured the System oscillator 0 to use the external 8 MHz crystal in Low power mode:
The MCG Is set to PEE and 48 MHz PLL output clock:
❗ It should be possible to use a 96 MHz PLL clock and then divide it down in the USB peripheral to a clock of 48 MHz. This is what I did first, and lost a lot of time, because this did not work :-(. I have not investigated it further, but this is either a bug in the silicon or in Processor Expert? 48 MHz without prescaler in the USB worked.
Derived from this, the system clocks are set up like this:
❗ IMPORTANT: Do not forget to set the PLL/FLL clock choice to ‘PLL clock’ as shown as last item in above screenshot.
In the Init_USB_OTG, the clock gate has to be enabled and the PLL/FLL clock to be used with 48 MHz:
❗ From the settings it would be possible to use a 96 MHz PLL clock and then to scale it down ot 48 MHz. However, with this my device did *not* enumerate 😦
That’s it! The rest is just writing a small test application.
The above project and sources are available on GitHub here. The same repository hosts the updated FSL_USB_Stack and FSL_USB_CDC_Device Processor Expert components.
Happy CDCing 🙂