These can come from the fall through of the switch statement cases for USB_EVENT_RESET, USB_EVENT_UNCONFIGURED and USB_EVENT_SUSPEND as the USB plug contacts make/unmake during plugging.
At the moment hal_serial_usb broadcasts a CHN_DISCONNECTED for each call to sduSuspendHookI(...) from usbfg.c and so there may be many CHN_DISCONNECTED events not balanced against CHN_CONNECTED events.
To reduce the CHN_DISCONNECTED events so that they are paired (mostly) with CHN_CONNECTED the serial USB driver can check if it is already suspended and not broadcast CHN_DISCONNECTED.
The below patch does that by checking the state of the queues.
This works although it is a bit "obtuse" so a more obvious solution might be warranted.
Code: Select all
Index: hal_serial_usb.c
===================================================================
--- hal_serial_usb.c (revision 12237)
+++ hal_serial_usb.c (working copy)
@@ -310,6 +310,8 @@
*/
void sduSuspendHookI(SerialUSBDriver *sdup) {
+ if(bqIsSuspendedX(&sdup->ibqueue) && bqIsSuspendedX(&sdup->obqueue))
+ return;
chnAddFlagsI(sdup, CHN_DISCONNECTED);
bqSuspendI(&sdup->ibqueue);
bqSuspendI(&sdup->obqueue);