Skip to main content
Visitor II
August 12, 2021
Question

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?

  • August 12, 2021
  • 2 replies
  • 1078 views

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?

    This topic has been closed for replies.

    2 replies

    Super User
    August 12, 2021

    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.

    DVars.1Author
    Visitor II
    August 12, 2021

    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?

    Super User
    August 12, 2021
    If you have VBUS connected to a pin, make it interrupt when it goes low. Or poll it periodically.