Skip to main content
Visitor II
April 2, 2020
Question

USB HID device enumeration and driver installation

  • April 2, 2020
  • 5 replies
  • 1523 views

Hello,

I have a STM32F042 as USB HID Keyboard done with STM32CUBEIDE. Everything works nicly. Now here is my problem. If I plug the device into a running Windows PC for the first time the driver installation appears and all is fine. However if I plug it into a turned off PC where it has not been installed previously the installation does not start. I have to unplug it and replug it for it to work. Now I wrote a sort of failsave routine that checks if the LED's have been set. If this doesn't happen for some time (if it was pluged in to a turned off PC that was then turned on) then it resets itself after some time, forcing a reenumeration. However it does still not work. I still have to unplug and replug it inspite of the reset. Is there a way of doing this with software and without the need of replugging? I somewhow need to cheet windows in thinking the device was unplugged and replugged.

    This topic has been closed for replies.

    5 replies

    Super User
    April 2, 2020

    The way the computer detects a device is when the DP or DM line gets pulled up. You can force re-enumeration by uninitializing the USB pins, then reinitializing. Probably need a small delay.

    machinistAuthor
    Visitor II
    April 2, 2020

    Thanks for the answer. But would this not happen anyway when I reset the device? Or do you mean I should manually set both lines to a low output after a reset and then after a short pause start the initialization of the USB?

    Super User
    April 2, 2020

    Reset will uninitialize the pins, but it doesn't add much of a delay. I would set a 1s delay and see what happens.

    machinistAuthor
    Visitor II
    April 2, 2020

    Ok I will try it, thank you!

    machinistAuthor
    Visitor II
    April 2, 2020

    Strangly it still does not work when plugged in before startup. I added a 5 second delay. I am thinking about adding a relay to disconnect, but that would be a filthy solution. Can anything break if I pullt the DP and DM lines low? Would that help?

    Super User
    April 2, 2020

    > Now I wrote a sort of failsave routine that checks if the LED's have been set.

    Which LEDs? Try to trace the enumeration process - does it start? Do you receive at least the reset event from the USBD controller?

    If not - look for electrical issue.

    -- pa