How to utilize USB1 on K66 with KSDK

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

How to utilize USB1 on K66 with KSDK

Jump to solution
2,456 Views
petershih
Contributor III

I am working on a USB application on our custom PCB with K66 MCU USB1 (Pin 25 and 26 on LQFP package). I had chance to try the HID keyboard device example on a TWR-K65F120M tower board USB0 with KSDK 1.3.0 and KDS 3.0.0. Similar implementation has be imported to my project. However, the project doesn't work.

Since I am working on the USB1, I have defined "#define HIGH_SPEED (1)" in order to allocate the "USBHS_BASE" at 400A_1000. However, the MCU stuck in the while loop in USB EHCI PHY initialization because the wrong crystal value and PLL cannot be locked. The crystal value in the firmware is 12MHz, which is the system oscillator on the K65 tower board. But this is not the main oscillator we used in our custom board. We use 50MHz oscillator in order to share the clock with Ethernet interface. Here I have several questions:

1. How do I specify for USB1, or USB0?

2. How do I specify full speed on the USB1? Is any example code provided for KSDK?

3. If the USB1 high speed is not required, do we still need to follow the rule "The system oscillator on EXTAL0 and XTAL0 is either of the following values,12MHz, 16MHz or 24MHz." provided in the K66 Sub-Family Reference Manual page 1682?

Tags (3)
0 Kudos
Reply
1 Solution
2,305 Views
jingpan
NXP TechSupport
NXP TechSupport

Hi Peter,

It seems it's impossible to use USB1 without 12/16/24M external clock input. The USBHS controller interfaces to the processor's core. The on-chip UTMI PHY supports high-speed(HS) applications, as well as full-speed and low-speed. This PHY can only have 480M clock from USBPHYPLLCLK. And this PLL's clock source can only be the external clock.

pastedImage_1.png

Regards,

Jing

View solution in original post

6 Replies
2,305 Views
mjbcswitzerland
Specialist V

HI

1) I think that you need to select the controller type in usb_host_config.h, whereby the EHCI - presumably HS controller is enabled by default. Since I don't use SDK I don't know full details but it is probably in the doc somewhere:

/* Host Controller Enable */
/*!
 * @brief host khci instance count, meantime it indicates khci enable or disable.
 *        - if 0, host khci driver is disable.
 *        - if greater than 0, host khci driver is enable.
 */
#define USB_HOST_CONFIG_KHCI (0U)

/*!
 * @brief host ehci instance count, meantime it indicates ehci enable or disable.
 *        - if 0, host ehci driver is disable.
 *        - if greater than 0, host ehci driver is enable.
 */
#define USB_HOST_CONFIG_EHCI (1U)

/*!
 * @brief host ohci instance count, meantime it indicates ohci enable or disable.
 *        - if 0, host ohci driver is disable.
 *        - if greater than 0, host ohci driver is enable.
 */
#define USB_HOST_CONFIG_OHCI (0U)

2. The HS USB PHY needs a 480 MHz clock for its operation (for its internal PLL), irrespective of whether it finally operates in LS/FS or HS mode (which depends on the device attached) so if you don't one of the crystal speeds that support this you can't use the HS USB controller, but you can still use the FS USB controller.


3. In device mode the FS USB also can operate in crystal-less mode and so is not dependent on the clock you use.
If you have a 50MHz crystal or oscillator you can use it for USB device or host with settings:
PLL input divide 5 (to give 10MHz input), 24x multiply to give 240MHz PLL output (120MHz core), select MCGPLLCLK as source to USB and SIM_CLKDIV2 to 0x00000009 (divide 5 with fraction set).

In the uTasker project this is highly automated so I just chose
K66,
not USB_HS_INTERFACE
#define CRYSTAL_FREQUENCY   50000000
#define CLOCK_DIV           5
#define CLOCK_MUL        24
and then its simulator conformed all operation in device and host modes and I could read the values that were set.

pastedImage_6.png

Regards

Mark

[uTasker project developer for Kinetis and i.MX RT]

0 Kudos
Reply
2,305 Views
petershih
Contributor III

Hi Mark:

Thank your reply. I have tried to use external oscillator you mentioned instead of internal PLL 480MHz PLL. However, I am still not able to make it work since the USB controller is not able to be reset during initialization.

We have been using KDS and KSDK for many years on several products. It will not suitable for us to switch track at this moment. I will still try to seek KSDK solution on how to drive USB1 FULL Speed capability without 12,16,24MHz main oscillator. Appreciate your feedback.

Regards,

Peter Shih

0 Kudos
Reply
2,306 Views
jingpan
NXP TechSupport
NXP TechSupport

Hi Peter,

It seems it's impossible to use USB1 without 12/16/24M external clock input. The USBHS controller interfaces to the processor's core. The on-chip UTMI PHY supports high-speed(HS) applications, as well as full-speed and low-speed. This PHY can only have 480M clock from USBPHYPLLCLK. And this PLL's clock source can only be the external clock.

pastedImage_1.png

Regards,

Jing

2,305 Views
petershih
Contributor III

Hi Jing:

Thanks your feedback. Based on you explanation, I understand the USB0 and USB1 have different interface. For USB1, I need to use 12M, 16M, or 24MHz as main oscillator in order to generate 480MHz USB clock. The USB0 doesn't have this limitation and will only support Full Speed USB.

0 Kudos
Reply
2,305 Views
myke_predko
Senior Contributor III

Hi Peter,

Before I would look at your questions 1. and 2. I would like to ask you why the choice of the 50MHz oscillator and not the values specified in the RM (Point 3.)?

AFAIK, you must have a 48MHz clock going into the USB module, which means that you need a base clock that can be divided/multiplied to 48MHz within the confines of the circuitry within the Kinetis.  I don't think this is possible with a 50MHz clock.  This should be the first issue that you need to address: get a 48MHz clock out at "USB FS clock" and see where you need to go from there.  

There is no single point of reference explaining Kinetis clocking and, while the clock tool in MCUXpresso is helpful, there's nothing that allows you to enter in your requirements and spit out a clock_config.c/.h file without you spending a lot of time learning about how clocking works and how to specify the various outputs to get exactly what you need.  If you look over the Community over the past few months, you'll see a lot of the hair pulling I went through learning it well enough to be able to specify the full speed operation of the MK22FN1M0Axxx12 used in my product as well as get the correct clock specification for the different hardware interfaces (including USB) that I am using in my product.

Here's the final result of that work:

2020.05.08 - Clocking on the MK22.jpg

Good luck!  

myke

2,305 Views
petershih
Contributor III

Hi Myke:

Thanks your feedback.

In our design, we use 50MHz oscillator as main oscillator in order to share the signal with RMII Ethernet requirement. As 50MHz external oscillator, we are able to work on 120MHz system clock. From here, we should be able to derive the 48MHz signal for USB module with full speed capability.

From my upstanding right now, it seems like the KSDK support Full Speed on USB0 with internal clock reference, and support USB1 with high speed capability, require 12,16, or 24MHz main oscillator for internal 480MHz PLL. Since our application doesn't require high speed USB, and the PCB has been designed on USB1. I think we should have a way to initialize USB1 with existing 50MHz external oscillator for full speed capability. I will keep trying on this. Thank you very much.

Best regards,

Peter Shih 

0 Kudos
Reply