cancel
Showing results for 
Search instead for 
Did you mean: 

Automatically reconnect to USB device after programming

ahansen
Associate

Hi.

I'm currently trying to develop a simple USB (CDC) application with an STM32 MCU that is configured using CubeMX. So far I have managed to make the device send some text message to my host machine which is displayed using a serial terminal program. But, I have noticed, that after programming new firmware to the target, I must physically disconnect and connect my board in order to reestablish the connection. I was wondering if there was a better way to do this ?

Best Regards,

abaldur

3 REPLIES 3
Pavel A.
Evangelist III

Disable the USB controller and wait several seconds, this works for me with MCUs that have internal resistor on USB data lines.

-- pa

ahansen
Associate

Hi Pavel.

Thank you for the answer. Can you be specific about how you disable the USB controller?

Will USBD_DeInit() be sufficient?

Best Regards,

abaldur

Pavel A.
Evangelist III

Yes, USBD_Deinit should call the right USB driver function (thru several layers added by CubeMX )

Note that the correct behavior depends also on the host side. When the USB device disappears, the host application should immediately close its handle or whatever. Otherwise re-enumeration can fail or create duplicate zombie device.

-- pa