Kinetis K65 USBHS Module setup issue

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

Kinetis K65 USBHS Module setup issue

475 Views
petec20
Contributor III

Platform: TWR-K65F180M

MCU: MK65FN2M0VMI18

Problem: USBHS module Host setup issue. This is a custom USB driver being written on the TWR-K65F180M platform. The USB HS port seems to be remaining disabled after a setup attempt.

The USB PHY has been initialised first and that seems okay - the PLL locks and the PFD indicates stable.

Then the USBHS module is initialised by doing this:

1). SIM_SCGC3[USBHS] = 1 ; enable USBHS module clock.

The datasheet says to make sure the USBHS controller has stopped before resetting it, so, as it may be a warm reset,

2) USBHS_USBCMD[RS] = 0 ; stop USB controller.

3) Wait for USBHS_USBSTS[HCH] to set, indicating the controller has stopped.

4) USBHS_USBCMD[RST] = 1 ; reset the USB controller.

5) USBHS_USBCMD[RST] = 0 ; release the USB controller reset.

The code gets stuck waiting for the controller to stop, at (3) above. If I ignore waiting for it to stop I have to enable the port by setting USBHS_PORTSC1[PE] and USBHS_PORTSC1[PP]. After that it correctly and reliably detects device attach events and their speed. However any attempt at device setup commands fail, I think this is due to USBHS_PORTSC1[PE] showing as being 0, ie that the port is actually disabled. I think this is possibly down to initial USBHS module setup.

QUESTION: Can somebody tell me the correct module/port setup order, especially with regard to the bits in the USBHS_USBCMD and USBHS_PORTSC1 registers? I have tried reading the C APIs for this but the state machine is not easy to read and I haven't had much success finding all the relevant pieces of code. An explanation in terms of plain English, without recourse to the example code, or in pseudo code would be much appreciated.

Labels (2)
Tags (4)
0 Kudos
0 Replies