Problem merging USB CDC and RTC demo

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Problem merging USB CDC and RTC demo

Jump to solution
797 Views
joebirch
Contributor III

I can't get Real Time Clock and USB CDC to work together.

 

I am using KDS 3.0, KSDK 1.2 on a FRDM_K22.

I am able to run the USB CDC demo: C:\Freescale\KSDK_1.2.0\examples\frdmk22f\demo_apps\usb\device\cdc\virtual_com\freertos\kds

and the RTC demo: C:\Freescale\KSDK_1.2.0\examples\frdmk22f\demo_apps\rtc_func\kds

separately but I have trouble combining them in a new project.

 

RTC works but CDC doesn't. I don't get a USB_DEV_EVENT_CONFIG_CHANGED event.

 

I zipped the project. There is a conditional compile ADDRTC. if undefined CDC works.

I think the problem is in BOARD_ClockInit() which is called for the RTC setup.

 

I appreciate the help

Joe

 

 


Original Attachment has been moved to: usb_cdc_rtc.zip

Labels (1)
Tags (2)
0 Kudos
1 Solution
492 Views
isaacavila
NXP Employee
NXP Employee

Hi Joe,

In fact, it is related to Clock settings on your configuration.

In K22, you can use either PLL, FLL or IRC48MHz clock to feed USB module. As you may know, USB needs a 48MHz input frequency in order to work correctly.

USB clock.jpg

In your case, when you don't add RTC support, clock configuration is set to produce a 48MHz output from PLL, this frequency feeds USB module (that sets divisor to 0) and CDC functionality works as expected. However, when you add RTC support and change clock configuration, PLL output is now 120MHz and it is passed as is to USB module (with USB divisors set to 0) so that is why USB does not work.

You can implement different solutions, one is, obviously, set PLL output to 48MHz (using clock configuration used when no RTC is added). Another is, to set USB clock reference to IRC48MHz instead PLL. I implemented the second one:

In Generated_Code/SDK/usb/usb_core/device/sources/bsp/usb_dev_bsp.c, i added the reference to IRC48MHz:

if (controller_id == USB_CONTROLLER_KHCI_0) {

    /* Disable USB clock gating */

    CLOCK_SYS_DisableUsbfsClock(controller_id);  

    /* Clock setting */

    /* Input clock source:      Auto select */

    /* Input clock frequency:   48 MHz */

    /* Input clock multiplier:  1 */

    /* Input clock divider:     1 */

    /* Module clock frequency:  48 MHz */

    CLOCK_SYS_SetUsbfsSrc(controller_id, kClockUsbfsSrcPllFllSel);

    CLOCK_SYS_SetPllfllSel(kClockPllFllSelIrc48M); //ADD this line to feed USB module from IRC48MHz

    /* USB clock divider */

    CLOCK_SYS_SetUsbfsDiv(controller_id, 0U, 0U);

    /* Enable USB clock gating */

    CLOCK_SYS_EnableUsbfsClock(controller_id); 

    /* Weak pull downs */

Obviously, this solution will be changed if you enable PE and generate code again. (I hardcoded your project this way due PE was disabled).

The best solution (using PE) will be to set USB clock settings in fsl_clock_manager component for the clock configuration 1 (the one that sets PLL to 120MHz)

Clock configuration.jpg


Again, I used the second solution and test it. Now CDC device is enumerating and working correctly when ADDRTC is defined.

I hope this can help you,

Best Regards

Isaac

-----------------------------------------------------------------------------------------------------------------------

Note: If this post answers your question, please click the Correct Answer button. Thank you!

-----------------------------------------------------------------------------------------------------------------------

View solution in original post

0 Kudos
2 Replies
493 Views
isaacavila
NXP Employee
NXP Employee

Hi Joe,

In fact, it is related to Clock settings on your configuration.

In K22, you can use either PLL, FLL or IRC48MHz clock to feed USB module. As you may know, USB needs a 48MHz input frequency in order to work correctly.

USB clock.jpg

In your case, when you don't add RTC support, clock configuration is set to produce a 48MHz output from PLL, this frequency feeds USB module (that sets divisor to 0) and CDC functionality works as expected. However, when you add RTC support and change clock configuration, PLL output is now 120MHz and it is passed as is to USB module (with USB divisors set to 0) so that is why USB does not work.

You can implement different solutions, one is, obviously, set PLL output to 48MHz (using clock configuration used when no RTC is added). Another is, to set USB clock reference to IRC48MHz instead PLL. I implemented the second one:

In Generated_Code/SDK/usb/usb_core/device/sources/bsp/usb_dev_bsp.c, i added the reference to IRC48MHz:

if (controller_id == USB_CONTROLLER_KHCI_0) {

    /* Disable USB clock gating */

    CLOCK_SYS_DisableUsbfsClock(controller_id);  

    /* Clock setting */

    /* Input clock source:      Auto select */

    /* Input clock frequency:   48 MHz */

    /* Input clock multiplier:  1 */

    /* Input clock divider:     1 */

    /* Module clock frequency:  48 MHz */

    CLOCK_SYS_SetUsbfsSrc(controller_id, kClockUsbfsSrcPllFllSel);

    CLOCK_SYS_SetPllfllSel(kClockPllFllSelIrc48M); //ADD this line to feed USB module from IRC48MHz

    /* USB clock divider */

    CLOCK_SYS_SetUsbfsDiv(controller_id, 0U, 0U);

    /* Enable USB clock gating */

    CLOCK_SYS_EnableUsbfsClock(controller_id); 

    /* Weak pull downs */

Obviously, this solution will be changed if you enable PE and generate code again. (I hardcoded your project this way due PE was disabled).

The best solution (using PE) will be to set USB clock settings in fsl_clock_manager component for the clock configuration 1 (the one that sets PLL to 120MHz)

Clock configuration.jpg


Again, I used the second solution and test it. Now CDC device is enumerating and working correctly when ADDRTC is defined.

I hope this can help you,

Best Regards

Isaac

-----------------------------------------------------------------------------------------------------------------------

Note: If this post answers your question, please click the Correct Answer button. Thank you!

-----------------------------------------------------------------------------------------------------------------------

0 Kudos
492 Views
joebirch
Contributor III

Isaac

Thank you for the detailed response. The fix works/!

Joe

0 Kudos