USBD app could be freeze when disconnecting the cable

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

cross mob
lock attach
Attachments are accessible only for community members.
Level 1
Level 1
First like received

USBD app 4.0.14 on XMC4xxx could be freeze in a infinite loop.

The problem is in the file
in function
93: while (Length)
94: {
95: if (ep->InInUse)
96: {
97: continue;
98: }

When trasmits a packet could happen the controller is busy because reading, so the driver wait
until rx finished.
Problem occurs when the driver is in this state and the user unplug the cable from the board.
InInUse flag is blocked to 1 and USBD is freeze in a infinite loop in this while().

I fix the problem adding a control that checks if USB_DeviceState is Unattached.
This stops the transfer and return an ENDPOINT_RWSTREAM_DeviceDisconnected error.

while (Length)
if (USB_DeviceState == (uint8_t)DEVICE_STATE_Unattached)
return ENDPOINT_RWSTREAM_DeviceDisconnected;
if (ep->InInUse)

In attachment the patch....

Is this fix okay to be merged to the next USBD app version?

Sirius Electronic Systems
0 Replies