plusk01 / airdamon_f3

Be the Matt Damon of the skies
2 stars 1 forks source link

VCP serial connection won't reconnect #7

Closed plusk01 closed 5 years ago

plusk01 commented 5 years ago

If the autopilot is being powered by the main power and the VCP USB connection is disconnected, it will not re-initiate the connection after USB is plugged back in.

plusk01 commented 5 years ago

It appears to be due to the packetSent flag in hw_config.c. This flag indicates if the last transmission is still working. It's value is the number of bytes are currently being processed to be sent. It is reset (letting others know the USB is clear to send more data) by EP1_In_Callback, which seems to get triggered when endpoint 1 (our usb vcp) has finished a transmission (not sure way it's called 'In' callback?)

My best guess is that when you unplug the usb, a deadlock occurs because the transmission is cancelled, but the packetSent flag will never be reset because the callback won't fire again.

In the debugger on the discovery board I manually set packetSent to 0 after a hotplug and VCP resumed as normal.

It seems like there should be some way of recognizing a disconnection event and we could reset packetSent there.

plusk01 commented 5 years ago

Found it (or at least, one that makes sense): Virtual_Com_Port_Reset in usb_prop.c.