cancel
Showing results for 
Search instead for 
Did you mean: 

USB HID device enumeration and driver installation

machinist
Associate III

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.

6 REPLIES 6
TDK
Guru

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.

If you feel a post has answered your question, please click "Accept as Solution".
machinist
Associate III

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?

TDK
Guru

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

If you feel a post has answered your question, please click "Accept as Solution".
machinist
Associate III

Ok I will try it, thank you!

machinist
Associate III

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?

> 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