tinyusb icon indicating copy to clipboard operation
tinyusb copied to clipboard

Draft: Add support for NXP Kinetis K28FA

Open pmiettinen opened this issue 1 year ago • 9 comments

This is an attempt to add support for NXP Kinetis K28FA. Effort is mostly based on the existing ports for kinetis_k32l2, mimxrt1170_evkb and the frdmk28fa_dev_composite_cdc_vcom_cdc_vcom_bm example in NXP MCUXpresso.

Unsure if the ci_hs driver is applicable here as is.

Current state of the port

Build OK:

tinyusb$ make -C examples/device/cdc_dual_ports/ BOARD=frdm_k28fa15 LOG=2 all
...
CREATE _build/frdm_k28fa15/cdc_dual_ports.hex

   text    data     bss     dec     hex filename
  26436     152   10260   36848    8ff0 _build/frdm_k28fa15/cdc_dual_ports.elf

make: Leaving directory '/home/pasi/git/tinyusb/examples/device/cdc_dual_ports'

Board boots up but doesn't seem to receive the setup message:

USBD init on controller 0
sizeof(usbd_device_t) = 51
sizeof(tu_fifo_t) = 12
sizeof(tu_edpt_stream_t) = 24
CDC init
USBD Bus Reset : High Speed
USBD Bus Reset : High Speed
USBD Bus Reset : High Speed
USBD Bus Reset : High Speed

Error messages on the Windows 11 host:

Windows has stopped this device because it has reported problems. (Code 43)

A request for the USB device descriptor failed.
Device settings for USB\VID_0000&PID_0002\6&28495545&0&2 were not migrated from previous OS installation due to partial or ambiguous device match.

Last Device Instance Id: USB\VID_045E&PID_07B2\9&1b254b8a&0&2
Class Guid: {36fc9e60-c465-11cf-8056-444553540000}
Location Path: 
Migration Rank: 0xF000FFFFFFFFF120
Present: false
Status: 0xC0000719

Porting guide suggests that this scenario indicates there's something wrong with the USB setup. This is possible but I am running out of ideas what to check. I took the clock config from the working MCUXpresso example and have been also otherwise comparing the projects but have not been able to find the relevant difference. Any tips what to check next? As a disclaimer, I have not worked with tinyusb earlier so I am likely to miss some obvious items too.

pmiettinen avatar Feb 08 '24 16:02 pmiettinen

Some extra info.

This is what I see with the working NXP example:

image

With my tinyusb port I see nothing in the wireshark.

pmiettinen avatar Feb 13 '24 16:02 pmiettinen

Looks like the dcd_reg->ENDPTSETUPSTAT is missed in dcd_int_handler because int_status & INTR_USB is not set at the same time.

pmiettinen avatar Feb 14 '24 08:02 pmiettinen

yeah, it should be ci_hs, try to compile with LOG=2 and checkout its output with either UART or segger rtt (LOGGER=RTT)

hathach avatar Feb 22 '24 11:02 hathach

yeah, it should be ci_hs, try to compile with LOG=2 and checkout its output with either UART or segger rtt (LOGGER=RTT)

If I didn't totally misunderstand, this is what I've already done? Please check the PR description. Additionally, I have observed the dcd_int_handler behavior in debugger and saw ENDPTSETUPSTAT going unhandled in the current logic.

pmiettinen avatar Feb 22 '24 12:02 pmiettinen

yeah, it should be ci_hs, try to compile with LOG=2 and checkout its output with either UART or segger rtt (LOGGER=RTT)

If I didn't totally misunderstand, this is what I've already done? Please check the PR description. Additionally, I have observed the dcd_int_handler behavior in debugger and saw ENDPTSETUPSTAT going unhandled in the current logic.

sorry my bad, look like it could be an clock/setup issue, each MCU will have slightly different clock setup. Unfortunately I don't have any K28 to test with. I will try to see if I could find a reasonable Kinets with hs usb from ebay. It may take a while though.

hathach avatar Feb 24 '24 10:02 hathach

By the way. I am seeing the same behavior on NXP MIMXRT1160-EVK secondary processor (M4). The primary core or M7 is working as expected. Just in case you have access to these boards more easily.

pmiettinen avatar Feb 24 '24 21:02 pmiettinen

By the way. I am seeing the same behavior on NXP MIMXRT1160-EVK secondary processor (M4). The primary core or M7 is working as expected. Just in case you have access to these boards more easily.

Oh, I don't have rt1160 but got 1170. Let me try to see if I could make a quick switch from m7 to m4 to compile with. However, they can be two different issues with different clock/pin configuration since these MCUs are totally different.

hathach avatar Mar 13 '24 13:03 hathach

By the way. I am seeing the same behavior on NXP MIMXRT1160-EVK secondary processor (M4). The primary core or M7 is working as expected. Just in case you have access to these boards more easily.

Oh, I don't have rt1160 but got 1170. Let me try to see if I could make a quick switch from m7 to m4 to compile with. However, they can be two different issues with different clock/pin configuration since these MCUs are totally different.

1170 should be fine. As a background, I did the M4 experiment in MCUXpresso. I took some M4 example as a base and then followed the tinyUSB porting guide replacing the NXP USB stack.

pmiettinen avatar Mar 13 '24 16:03 pmiettinen

Just ordered an frdm k66f from ebay to test out this pr. Couldn't find a k28, but I guess it would be much more similar than rt1170. It will take a month or so for it to be delivered to my desk so please be patient.

hathach avatar Apr 06 '24 01:04 hathach