Detect USB disconnection

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
User8819
Level 4
Level 4
Hello,

I am using WINUSB example on xmc4400 to connect it in device mode to PC host. I am not using P0.9 as USB.ID. Is there a way how to detect internaly that USB has been unplugged from PC?

Thanks

rum
0 Likes
7 Replies
Not applicable
Hello Rum,

Are you using DAVE3 or DAVE4 for the example?

Best regards,
Angel
0 Likes
User8819
Level 4
Level 4
I am using dave3. The question is why otg session end interrupt is never triggered when Vbus voltage is disconnected from device. Any other suggestions?
0 Likes
AngelB
Employee
Employee
Hi Rum,

unfortunately without connecting the P0.9 USB.ID the OTG disconnect Interrupt will not be generated.

But some workarounds can be used. For example, in the currently public DAVE3 USBD APP we are not handling the disconnection-reconnection but in the USBD APP for DAVE4 we handle the disconnection-reconnection without the OTG Interrupt by monitoring the Resume Event.
If the Resume Event is detected and the SetConfiguration request has not been yet recieved, the device has been reconnected after a disconnection, so the internal buffers and indexes can be released.

BTW, we will release soon a new version of the USBD APP for DAVE 3 including the handling of the disconnection-reconnection.

Best regards,
Angel
0 Likes
User8819
Level 4
Level 4
Hi AngelB,

1 . Why there is no event when VBUS voltage is disconnected?

2. What is the purpose of OTG comparators - there is no description in manual.

3. I need to detect disconnection. Seems that your answer regards re-connection using resume event.

3. Another question, what is the purpose of following line under conditional compilation in xmc4_usb.c driver file? Should be removed if dave is not used?

#ifdef DAVE_CE
xmc_device.DeviceEvent_cb(USB_USBD_EVENT_SOF);
#endif

Thank you

rum
0 Likes
AngelB
Employee
Employee
Hello Rum,

1. The OTG disconnection Event is generated after the presence/abscense of an ID Connection. So without connecting ID pin the OTG disconnection Event is not generated.
2. The part of the PHY which implements the OTG functionality.
3. For detecting the disconnection Event you can try to implement the secuence described in the section 13.4.3 of the xmc4200(for the non-OTG disconnection) reference Manual:

The device disconnect flow is as follows:
1. When the USB cable is unplugged or when the VBUS is switched off by the Host, the
device core triggers GINTSTS.USBRst [bit 12] interrupt bit.
2. When the device application detects GINTSTS.USBRst, the application sets a timeout
check for set address control transfer from host.
3. If application does not receive set address control transfer from host before the timeout
period, it is treated as a device disconnection.


4. In DAVE 3 we use this macro for identifying the DAVE enviroment. We were, in the past,not supporting the Start of Frame Event in other 3rd Party Tool where we were using the same library.

Regards,
Angel
0 Likes
Not applicable
Hello AngelB,

is the improved USBD App for DAVE 3 still to be released or has it been cancelled?


AngelB wrote:

BTW, we will release soon a new version of the USBD APP for DAVE 3 including the handling of the disconnection-reconnection.
0 Likes
DRubeša
Employee
Employee
First solution authored First like received
HI,

so there are no further plans for updating DAVE 3 version of an APP, so I suggest to migrate to DAVE 4 version of an APP. Sorry for any inconvenience this may cause.

Best regards,
Deni
0 Likes