[MQX4.1]: Can USB Device Stack Sense a USB Soft-detach

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

[MQX4.1]: Can USB Device Stack Sense a USB Soft-detach

603 Views
huishao2
Contributor IV

Hi-

My device is a self-powered CDC device and I want it to have capability of sensing a soft-detach. It is required to have USB interface physically connected. Due to power constraints, the USB host can only start enumerating or detaching device by closing/opening switch on D+/D- periodically. The host has full control over attachment and detachment by receiving attach event and detach event from USB host stack. I want to have similar notification from USB device side. Now my question is, is there similar attach event and detach event sent out from USB device stack due to opening/closing of D+/D-?

Thanks and regards

Hui

0 Kudos
3 Replies

429 Views
isaacavila
NXP Employee
NXP Employee

Hello Hui,

Unfortunately, there is no way to detect a Device detachment via software, however, as you are using a self-powered device, you can monitor the 5V voltage from USB connector, this is, if device is connected to a host, the host will provide 5v from that line so you can detect that your device is plugged or unplugged according voltage level on that line.

To make this, you can configure one GPIO as input and see voltage level on this 5V line (this GPIO should be 5V-tolerant, otherwise, you should add a voltage divider to avoid damage on MCU). This way, if you previously had 5V on this line and suddenly it appears as 0V, it means a detachment event occurred.

I hope this can help you!

Best Regards

Isaac Avila

----------------------------------------------------------------------------------------------------------------------------------------

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

----------------------------------------------------------------------------------------------------------------------------------------

0 Kudos

429 Views
huishao2
Contributor IV

Hi Isaac,

Thanks for your reply!

Unfortunately, the USB connector is required to be connected consistently in this special case. So I have no way to see changes over Vbus.

My test shows, however, I can receive USB_APP_ERROR from callback upon manually breaking D+/D- after device power cycle. I wish this is helpful to me but this event disappeared after I tried a few times of closing/opening D+/D-.

Any suggestions?

thanks!

Hui

0 Kudos

429 Views
isaacavila
NXP Employee
NXP Employee

Hi Hui,

USB_APP_ERROR event is received when an error occurs in any of the USB state machine's states, so probably, when device was in middle of a transaction, you could get the USB_APP_ERROR event (because this transaction wasn't finished) and in other cases, no transactions were taking place when detachment occurred and that is why you didn't received the event.

I think the only way to detect this event (detachment) will be monitoring the VBUS voltage.

Sorry for all inconvenience it may cause.

Best Regards,

Isaac