cancel
Showing results for 
Search instead for 
Did you mean: 

How does USB reconnect with the PC without being pulled out?

1123
Associate II

My board is STM32f072B

But I have a question, I can plug and reconnect to the PC in USB, but I think it is too much trouble and take time.

Is there any way to reconnect without pulling the USB cable PC?

1 ACCEPTED SOLUTION

Accepted Solutions

By toggling USB_BCDR.DPPU.

You also have to restart the whole USB stack, of course.

JW

View solution in original post

7 REPLIES 7

By toggling USB_BCDR.DPPU.

You also have to restart the whole USB stack, of course.

JW

I ask a question,

If you use the USB BCDR.DPP register bit, his DRDD register bit is device address, then will he re-determine it?

Pavel A.
Evangelist III

Of course. The host will re-enumerate the device and may assign a different address.

-- pa

Alex R
Senior

ALternatively, you can use a Programmable USB Hub that allows you to disconnect the USB Port (data and/or power) at will.

See:

https://acroname.com/store/s77-usbhub-2x4?sku=S77-USBHUB-2X4

You can use to implement automatic tests for USB enumeration,etc.

doss
Associate II

You also could build a "disconnect-cable".

This pdf is the schematic to a random stm32 board I know about. It has a transistor that switches a pullup to enable/disable USB.

https://github.com/spacerace/HY-MiniSTM32V/raw/master/HY-MiniSTM32V_SCH.pdf

On on page 3 see the section "USB device". You could cut an USB cable, build that thing with the transistor+4 resistors+LED and solder it between the cable's plugs.

You don't need the 22r resistors there, they are already on your board.

You connect DP, DM and GND for USB connection and VCC for the pullup/transistor supply. The transistor input ("USB EN") goes with a switch to GND. You could also connect to a port pin instead of a switch and everytime you do a reset, your program takes care about this.

I haven't built this solution by myself, I have it on one of my dev-boards. It works fine.

Once I tried to just switch the DP and DM lines with a 2-pole-onoff-switch, but I had problems with USB connections. I thought it was due to dirty contacts and ringing on the line and abandoned this.

But given the low effort to build this, I think it is worth a try - with a switch that was not lying around in boxes for 25 years...

The maple mini boards use a similar circuit.

Also you could do this:

Upon reset, before initializing USB, you could configure DM and DP pins on your microcontroller to regular GPIO outputs and pull them low for a few ms and then high for a few ms and go on with regular initialization.

1123
Associate II

i try use USB BCDR.DPP register bit, .

He can use it, and it will be disconnected and reconnected very smoothly.

Thank you for your help.

WBieg
Associate II

i'm using micro instruction RESTART_USB; and time delay HAL_Delay(500); before MX_USB_DEVICE_Init();

#define RESTART_USB 	do{GPIO_InitTypeDef GPIO_InitStruct = {GPIO_PIN_12, GPIO_MODE_OUTPUT_PP};\
	HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);\
	HAL_GPIO_WritePin(GPIOA, GPIO_PIN_12, GPIO_PIN_RESET);}while(0)
RESTART_USB;
HAL_Delay(500);
MX_USB_DEVICE_Init();