[MQX 4.1.1]: is USB host stack able to control the start of D+ activity?

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

[MQX 4.1.1]: is USB host stack able to control the start of D+ activity?

568 Views
huishao2
Contributor IV

Hi-

My project includes a USB CDC host and USB CDC device. Host is k20d72m based while device is k20d50m powered. I have upgraded both USB stacks to MQX4.1.1 version. When device is attached to host, host is to power on and  off periodically the device for measurement polling. Once the device is plugged in, the USB host stack is loaded and stays for next round of poweron - enumeration - poweroff - "detach", until device is detached physically. My problem is that this operation only works for the first time when device is plugged in and fails on all subsequent "attachment".

Further investigation shows the problem is due to the fact that device bootup latency is over 150ms and that makes it miss the USB BUS Reset Condition from the host. The consequence is the device refuses the enumeration process. So question is, is there a way to postpone USB activities on the bus, particularly on D+ until my device is properly finishes bootup?

What I can share with folks is that as a workaround, I hacked the USB host stack in khci.c to postpone the appearance of Reset Condition:

static void _usb_khci_attach(USB_KHCI_HOST_STATE_STRUCT_PTR usb_host_ptr) {
    USB_MemMapPtr usb_ptr = (USB_MemMapPtr) usb_host_ptr->G.DEV_PTR;

    usb_ptr->ADDR = 0;
    _time_delay(300); /* orig 100 */

    // speed check, set
    usb_host_ptr->G.SPEED = (uint_8)((usb_ptr->CTL & USB_CTL_JSTATE_MASK) ? USB_SPEED_FULL : USB_SPEED_LOW);
    if (usb_host_ptr->G.SPEED == USB_SPEED_FULL)

Another issue with the USB host stack is that many times of loading/unloading stack will cause system crash on my host. I am wondering if this is the case someone else have seen. Load the stack at USB plugin and unload it at USB plugout, try this many times.

Thanks!

Hui

0 Kudos
1 Reply

346 Views
RadekS
NXP Employee
NXP Employee

Unfortunately there isn’t any “official” way how to postpone USB activities on the bus.

If both (host and device) stack are in your hand, you can do it by this hack (increase _time_delay).

I guess that correct way should be rather that host try reset device after some time from point where enumeration fails, again and again.


Have a great day,
RadekS

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