cancel
Showing results for 
Search instead for 
Did you mean: 

When i disconnect and connect USB cable, while using USB-CDC i get 16 bytes previously loaded to the driver, how can i remove them?

DVars.1
Associate II

Every period of time i send ~33bytes through USB CDC, if suddenly USB cable disconnected and reconnect i get 16 bytes of the last message loaded, and then continue to get new messages.

How can i detect disconnection and were these 16 bytes located?

3 REPLIES 3
TDK
Guru

Sounds more like a windows driver issue than an STM32 thing. Windows should be able to detect when it's unplugged (COM port goes away). Use a USB monitor to see if the actual data on the line includes the 16 bytes.

You can reset the USB peripheral on disconnect (VBUS goes low) and reinitialize to stop whatever ongoing transaction it's doing.

If you feel a post has answered your question, please click "Accept as Solution".
DVars.1
Associate II

Actually it happens on Linux. Linux allow re-connection.

On Windows the communication does not recover after re-connecting the cable, It requires resetting the device in order to reconnect.

Is there a event on VBUS changes?

If you have VBUS connected to a pin, make it interrupt when it goes low. Or poll it periodically.
If you feel a post has answered your question, please click "Accept as Solution".