2 Replies Latest reply on Oct 17, 2017 1:02 AM by JuRo_640956

    Detecting USB disconnection (self powered)


      Hi, I'm a bit new to USB device design and have a fairly straight forward question about connection state. 


      My application is a keyboard style piece of hardware that has custom buttons, USBFS with three HID end points for keys, mouse and volume control. It's always powered and always connected to an Embedded X86, running Windows 10 or similar. The OS will reboot many times during the users day, because Windows is like that, and each time, my device will stop working, requiring a full power cycle to bring us back.


      I need to detect the USB disconnection by host... right now I'm using USBFS_1_bGetConfiguration, and clearly it is returning a != 0 value even after the OS has shut down. 


      Should I be using isConfigurationChanged()? This would let me see the OS come up, then I'd reInit the USBFS, use USBFS_1_bGetConfiguration to confirm a connection and load each end point? I'm working on this now with no success yet.




      Thanks, Brent. 

        • 2. Re: Detecting USB disconnection (self powered)

          Regarding improvement suggestion for KBA210620:


          It might be worth mentioning that some psoc usb examples have the potential to get hung

          if the unplug event occurs at a special time.

          so that the VBUS monitoring stuff in the main loop can not do its work anymore.

          e.g. code lines like:



          KBA210620 should give advices (or links) for this problem also:
          - like calming a  watchdog only in the VBUS monitoring section
          - doing VBUS monitoring in a periodic ISR

          - hints how to avoid potential endless llops


          My preliminary approach

          void SysTickISRCallback(void)


              static unsigned int count = 0;

              if(count > 50)


                  count = 0;

                  if (!USBFS_VBusPresent() && usbEnumerated)












          1 of 1 people found this helpful