2020-04-02 05:57 AM
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.
2020-04-02 06:31 AM
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.
2020-04-02 06:33 AM
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?
2020-04-02 06:38 AM
Reset will uninitialize the pins, but it doesn't add much of a delay. I would set a 1s delay and see what happens.
2020-04-02 06:41 AM
Ok I will try it, thank you!
2020-04-02 11:43 AM
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?
2020-04-02 12:54 PM
> 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