MK66 USB device is not detecting ?

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

MK66 USB device is not detecting ?

Jump to solution
3,717 Views
karthikas
Contributor IV

I am working with MK66FN2M0VLQ18 MCU in our customized board.for the USB device mode.(USB High speed mode).

I have downloaded SDK_2.0_MK66FN2M0xxx18 , and running USB_DEVICE_CDC_VCOM .

It was running upto APPTASK() without any problem , but It has stopped in APPTASK(), and device is not getting detected in PC. 

Can anyone help me in resolving the issue as soon as possible.

Thank you.

1 Solution
2,602 Views
cutworth
NXP Employee
NXP Employee

Hi Karthik,

Before you call USB_DeviceRecvRequest after you received kUSB_DeviceEventSetConfiguration event, did you initialized the bulk endpoint with something like USB_DeviceMscEndpointsInit?

Did you have a chance to trace the USB_DeviceRecvRequest? I looked at the internals for this function and cannot find a code path which will set return value to kStatus_USB_Error, it will finally set to other return values, either success or other error code. So I need to know which error actually occurred.

For your case, it's not suggested you call USB_DeviceMscRecv or USB_DeviceMscSend for sending bulk in or out data. These two functions is for MSD class which has some layer added upon the bulk endpoint, so data is send in CBW and CSW stage.

Hao

View solution in original post

24 Replies
2,536 Views
cutworth
NXP Employee
NXP Employee

Hi Karthik,

Could you share complete schematic for HS USB part? It's not very clear from the image you shared. What's the output on VREG_OUT pin when you plug in USB cable to PC?

Hao

2,536 Views
karthikas
Contributor IV

Hii.,Hui_Ma & Cutworth Wang.,

Sorry for the late reply,Actually I was on  vacation.

I have customized the USB moss storage(usb_msc_ramdisk) example as per our requirement, I have changed class & subclass to '0', the device is getting detected and working with our customized PC driver. Now two bulk endpoints are available to send & receive data other than control enpoints.

I want to send and receive data through bulk endpoints, Is there send & receive functions already available in usb_msc_ramdisk example, or else which functions I have to use in usb_msc_ramdisk example.  And which is receive status flag.

0 Kudos
2,536 Views
cutworth
NXP Employee
NXP Employee

Hi Karthik,

I suppose you are using KSDK2.0 code. You can refer to usb_device_msc.c file. Send and receive function with MSC buld endpoint is as follows.

usb_status_t USB_DeviceMscSend(usb_device_msc_struct_t *mscHandle);

usb_status_t USB_DeviceMscRecv(usb_device_msc_struct_t *mscHandle);

The receive status flag you asked for is kUSB_DeviceMscEventReadRequest which is inside USB_DeviceMscCallback function. The callback is called inside USB_DeviceMscRecv with code like below and USB_DeviceMscBulkOut for bulk OUT endpoint callback function will call USB_DeviceMscRecv.

mscHandle->configurationStruct->classCallback((class_handle_t)mscHandle, kUSB_DeviceMscEventWriteRequest, &lba);

Hao

2,536 Views
karthikas
Contributor IV

Hai  Cutworth Wang.,

I am waiting for your reply. How do I implement send & receive function, where do I get endpoints event(Bulk_IN & Bulk_OUT). Because of I am using  USB moss storage(usb_msc_ramdisk) example, it has so many function which are not related to my requirement, I need to modify this and implement simple send & receive functions through Bulk endpoints available.

While enumeration process I have modified configuration and device descriptors, and enumeration process happens perfectly , usb device also getting detected, But here after I got stuck. 

Now USB device enumeration got completed and two Bulk endpoints are available, Could you please help me in writing & reading data from this endpoints.

Please get back to me as soon as possible.

Thank you..., 

karthik AS

0 Kudos
2,536 Views
cutworth
NXP Employee
NXP Employee

Hi Karthik,

I understand what you need now. You intend to bypass the logic for MSC and just use the BULK endpoint to send and receive data right?

Let explain how the USB stack works when it tries to send and receive data with its endpoints.

When USB device receives either IN or OUT token from USB host, it will call USB_DeviceNotification() inside usb_device_dci.c file. At the end of that function, you will see the following code which calls registered endpoint callback function.

/* Call endpoint callback */
error = handle->endpointCallback[(uint8_t)((uint32_t)endpoint << 1U) | direction].callbackFn(
handle, &endpointCallbackMessage,
handle->endpointCallback[(uint8_t)((uint32_t)endpoint << 1U) | direction].callbackParam);

The prototype of this endpoint callback is inside usb_device.h

typedef usb_status_t (*usb_device_endpoint_callback_t)(usb_device_handle handle,
usb_device_endpoint_callback_message_struct_t *message,
void *callbackParam);

For the MSD disk demo, you will see USB_DeviceMscEndpointsInit function called inside USB_DeviceCallback function once USB passed enumeration and received kUSB_DeviceEventSetConfiguration event. Inside USB_DeviceMscEndpointsInit function, it registered both USB_DeviceMscBulkIn and USB_DeviceMscBulkOut as BULK IN and OUT endpoint callback function. The prototype is the same as the endpoint callback function. Here you can redefine what you need to send and receive data on BULK endpoints.

 

Hao

2,536 Views
karthikas
Contributor IV

Hai Cutworth Wang.,

Thank you for the reply.

Yes I understood the USB stack working . Once device get enumerated I am getting kUSB_DeviceEventSetConfiguration event , there I am trying to call receive function. but receive function returning kStatus_USB_Error.

 I am calling this function  >>

extern usb_status_t USB_DeviceRecvRequest(usb_device_handle handle,uint8_t endpointAddress,uint8_t *buffer,uint32_t length);

with Bulk out end point address.

Can you please tell where I did mistake or how do use these functions to receive and send data to PC.??

If I need to use 

usb_status_t USB_DeviceMscRecv(usb_device_msc_struct_t *mscHandle);
usb_status_t USB_DeviceMscSend(usb_device_msc_struct_t *mscHandle);

these function, which one is the mscHandle pointer. And how can I modify these function to call send and receive function with Bulk endpoints.

Please get back to me soon..

Thank you..

Regards .,

Karthik

0 Kudos
2,603 Views
cutworth
NXP Employee
NXP Employee

Hi Karthik,

Before you call USB_DeviceRecvRequest after you received kUSB_DeviceEventSetConfiguration event, did you initialized the bulk endpoint with something like USB_DeviceMscEndpointsInit?

Did you have a chance to trace the USB_DeviceRecvRequest? I looked at the internals for this function and cannot find a code path which will set return value to kStatus_USB_Error, it will finally set to other return values, either success or other error code. So I need to know which error actually occurred.

For your case, it's not suggested you call USB_DeviceMscRecv or USB_DeviceMscSend for sending bulk in or out data. These two functions is for MSD class which has some layer added upon the bulk endpoint, so data is send in CBW and CSW stage.

Hao

2,536 Views
karthikas
Contributor IV

Hai Cutworth Wang.,

Thank you so much for your help,  yes some small modification need to be done in  USB_DeviceMscEndpointsInit , now the device is able to receive data from the PC.

But once I receive data, data receive response is not sending from controller that is why if I send data again from PC it was getting stall error, how do I resolve this and How do I get Call back  function Like USB_DeviceMscCallback . Is there any modification need to be done in endpoint call back function.

Thank you.,

Regards.,

Karthik

0 Kudos
2,536 Views
cutworth
NXP Employee
NXP Employee

Hi Karthik,

So did you change the USB_DeviceMscBulkOut as well so the BULK OUT endpoint callback is handled? Basically what you need to do is to get BULK OUT endpoint ready for next BULK OUT transfer by calling USB_DeviceRecvRequest if you expect PC will send more data.

Hao

0 Kudos
2,536 Views
karthikas
Contributor IV

Hai Cutworth Wang.,

Thank you very much for the help, USB moss storage example working fine and board can able to send & receive data from PC.

Now I tried to extract the code from SDK2.0 stack to create my own project, but it was giving number of error. I just created empty project and copied all file including start up files and all header file from stack. 

How do I create my own project in our specified folder, and I don't want to link header files from other place, all the files I am using need to be in my project folder.

Thank you.,

usb_screenshot.png

0 Kudos
2,536 Views
cutworth
NXP Employee
NXP Employee

Hi Karthik,

You can download the project generator tool from KSDK page and use it to create or clone a KSDK based project. It can be a standalone project.

Software Development Kit for Kinetis MCUs|NXP 

Hao

2,536 Views
karthikas
Contributor IV

Hai Cutworth Wang.,

 

       I need to clarify few things related to MCU (MK66) .

>> If I use USB1(USB-HS) in host mode, Can I connect USB hub of 1:4 or 1:8 to the USB port. If so which of example I should use in  SDK_2.0_MK66FN2M0xxx18 stack.

>> And Can I use both USB0(USB-LS) & USB1(USB-HS) at a time.

Thank you.,

 

 

Regards

Karthik 

0 Kudos
2,535 Views
cutworth
NXP Employee
NXP Employee

Hi Karthik,

I think you can use any of the SDK2.0 example for USB host demos. Hub support is inherent with SDK2.0 stack. You can find hub support code under middleware\usb_1.4.0\host\class folder.

pastedImage_1.png

Yes, you can use FS and HS module at the same time. But as the USB regulator output is shared by both USB module, there are precautions you need to take care on how to connect VBUS on USB connectors to VREGINx of K66. 

Hao

0 Kudos
2,535 Views
karthikas
Contributor IV

Hai Cutworth Wang.,

Thank you for the reply.,

In SDK2.0 example I found USB host CDC,audio,Moss storage disk,HID mouse & PHDC example. How do I start with these example so that I need to connect USB hub of either 1:4 or 1:8. And through that USB hub Can I connect Multiple USB device like Mouse,USB Moss storage device or any other USB devices.

> Can I configure USB hub to connect different class device.

>> Now I need to use both USB0(USB-FS) as VCOM device and USB1(USB-HS) in Host mode to connect USB hub. Does it possible with MK66 MCU or else I need use any USB controller. 

I worked on USB device mode but very New to USB host mode.

Can you please clarify me about these things and track me how do I start. ?

Thank you.,

Regards.,

Karthik

0 Kudos
2,535 Views
cutworth
NXP Employee
NXP Employee

Hi Karthik,

OK, I got what you mean now. Current SDK USB host demo support is one example code just support one USB class. You need to change code to have it support multiple USB class. I have not tried such use case yet so I do not have much comment on how to change.

For your use case, it's possible, you can use USB-FS as USB device while USB-HS as USB host. But you may need to consider if the USB device is self-power or bus-power and how you can make sure the USB regulator output works for both USB module. 

Hao

2,535 Views
karthikas
Contributor IV

    Hai Cutworth Wang.,

  As I mentioned earlier , I using sdk2.0 USB device example .

 The USB interface is working and I can send/receive data, but if I run the controller in High speed clock run mode its not working.

if I change Board_BootClockRUN(); with Board_BootClockHSRUN() then USB is not working , It getting stuck inside USB init function.

Thank you.,

Best Regards

Karthik

0 Kudos
2,536 Views
karthikas
Contributor IV

Hai Cutworth Wang.,

No I didn't modify anything in USB_DeviceMscBulkOut and Bulk OUT endpoint callback functions. 

Yes once data received I am calling USB_DeviceRecvRequest again, but still its giving Stall error  when I send data from PC. I think its because of acknowledgment for the first reception was not done from controller to PC , that is why PC is still waiting for acknowledgement.

And If call back function is properly handled, when data received from PC one of the following event in USB_DeviceMscCallback should come

case kUSB_DeviceMscEventReadResponse:

case kUSB_DeviceMscEventWriteResponse:

But these events are not occurring even after data received successfully.

Thank you.,

Regards

Karthik 

0 Kudos
2,536 Views
Hui_Ma
NXP TechSupport
NXP TechSupport

Hi

I had tested the KSDK V2.0 [usb_device_cdc_vcom]  example on FRDM-K66F board without any problem.

Could you double check the High speed USB related circuit with FRDM-K66F board schematics? The FRDM-K66F board schematics could be downloaded from here.


Wish it helps.

Have a great day,
Ma Hui
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

2,536 Views
Hui_Ma
NXP TechSupport
NXP TechSupport

Hi

Could you try to remove C6 & C7 capacitors at USB_D+ and USB_D- pin?


Wish it helps.

Have a great day,
Ma Hui
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos
2,536 Views
karthikas
Contributor IV

Thank you for the reply.

i have made some hardware changes, now the hardware side i don't have any problem but , I have some problem in USB driver. The device is not properly detecting, In PC its showing unknown device, also I tried to update driver but its not happening. I have checked the properties of unknown device it doesn't have any information like PID,VID etc.

I have debug the code , I am getting reset interrupt, but not getting SOF(start of frame interrupt) instead i am getting port change interrupt ,what's the mistake, Is there any changes has to be done in SDK_2.0_MK66FN2M0xxx18 stack.

thank you..,

0 Kudos