Disconnecting from USB - Page 1
Forum section: electronics / beginners

author: fabiodl
author_rank: Frequent Contributor
timestamp: January 30, 2021, 03:04:15 am
content: The CH559 microcontroller requires to hold a pin down while connecting to the usb (probably when receiving power) to enter in program mode. Is it ok to disconnect only the power while leaving D+/D- connected?Is it bad for the usb port/microcontroller ?If I only interrupt vcc, then D+/D- may be at an higher voltage than VCC.What circuitry would you use to properly disconnect and reconnect the microcontroller to the USB?A 4PDT switch? or are there more elegant approaches?

author: bob91343
author_rank: Super Contributor
timestamp: January 30, 2021, 07:08:45 am
content: Your question needs to be reworded. Run on sentences and unclear descriptions won't get useful answers.

author: m k
author_rank: Super Contributor
timestamp: January 30, 2021, 10:55:24 am
content: USB power contacts are longer for a reason.Disconnecting + only should be quite safe.

author: fabiodl
author_rank: Frequent Contributor
timestamp: January 31, 2021, 03:11:40 am
content: That is exactly why they are longer. This means that they are the first to connect and the last to disconnect. But if I put a switch, they will be the first (actually the only) to disconnect when I switch off.

author: jfiresto
author_rank: Frequent Contributor
timestamp: January 31, 2021, 07:15:33 am
content: Quote from: fabiodl on January 31, 2021, 03:11:40 amThat is what I do to "plug" and "unplug" a mirrorless camera from its USB 2 host. Attached are the relevant bits to chew on. They are not very high tech and do not abuse the USB standard abominably.

author: oPossum
author_rank: Super Contributor
timestamp: January 31, 2021, 08:04:33 am
content: Quote from: fabiodl on January 30, 2021, 03:04:15 amThe bootloader can be jumped to from user code so you can add something to your code to allow reprogramming without having to disconnect power. For example I have written USB to UART (CDC ACM) code that will jump to the bootloader when the bitrate is set to 8007 (BOOT).

author: fabiodl
author_rank: Frequent Contributor
timestamp: January 31, 2021, 10:14:53 am
content: Quote from: jfiresto on January 31, 2021, 07:15:33 amThank you, I wonder how are the D+/D- connected? it appears they are constantly connected, even when VBUS is disconnected.Quote from: oPossum on January 31, 2021, 08:04:33 amThank you, that is neat. I just saw a similar trickhereSince I am spinning a dev board,I'd like to have some hardware solution as well.

author: jfiresto
author_rank: Frequent Contributor
timestamp: January 31, 2021, 10:54:15 am
content: Quote from: fabiodl on January 31, 2021, 10:14:53 amThat is right: ground, D+ and D- remain connected to the (camera) device. If you study the USB 2.0 standard, you can see how its requirements can make that work.

author: Ian.M
author_rank: Super Contributor
timestamp: January 31, 2021, 11:22:20 am
content: Most MCUs with USB bootloaders that activate on USB connection when a pin is in a particular state, will also enter the bootloader if you hold the pin in the required state and reset the MCU. I'm unable to find an English language CH559 datasheet to confirm it will do this, but as thisCH559 dev boardhas directly adjacent 'Rst' and 'Prog' buttons its likely that you *can* enter programming mode with a simple rolling finger-press that holds 'Prog' after 'Rst' is released long enough for it to enumerate.

author: fabiodl
author_rank: Frequent Contributor
timestamp: January 31, 2021, 01:30:23 pm
content: I tried with resetting while holding the pin down, but it did not work.Unluckly the chip is reset, but it seems to skip the bootloader and jump to the user program.

author: Ian.M
author_rank: Super Contributor
timestamp: January 31, 2021, 02:44:36 pm
content: Hmmm. You *could* externally force a SE0 state on D+ and D- for >10ms.That should cause a disconnect and possibly also a peripheral device reset.According to the USB 2.0 standard, any compliant host or device port must be able to withstand the data lines being shorted to ground for up to 24H without damage. See 'Short Circuit Withstand' p124 (PDF p152)To avoid significantly loading D+ and D-, I would suggest two low capacitance Schottky diodes (as VOL(max)is 0.3V), anodes to the data lines with minimum length or preferably no stubs, with *either* a pullup to Vbus on their common cathode (to keep them strongly reverse biased for minimum capacitance) and a switch or N-MOSFET to pull the cathodes down to ground, *or* drive the cathodes from a 5V CMOS logic gate.N.B. There is a small risk that some non-standards compliant 'USB compatible' devices may not tolerate shorting the data lines to bus ground.

author: ledtester
author_rank: Super Contributor
timestamp: February 04, 2021, 11:45:57 am
content: There are numerous USB hubs with a "power" switch for each port - you could see if they do anything special, e.g.:https://youtu.be/-2EXj5G5MkEUpdate:This might be a better teardown video:https://youtu.be/4RfMiyjQ12s

author: oPossum
author_rank: Super Contributor
timestamp: February 07, 2021, 07:46:15 am
content: A have a few USB hubs with power switches. They all use single sided PCBs and the signal integrity is bad enough that CH55x chips don't work reliably. Spent some time trying to determine why my code wasn't reliable and it turned out to be the USB hub.

author: oPossum
author_rank: Super Contributor
timestamp: February 07, 2021, 08:07:04 am
content: Quote from: Ian.M on January 31, 2021, 11:22:20 amUnfortunately CH55X do not work this way. The bootloader runs at powerup only. The only way to get back into it again without a power cycle is for user code to jump to it.

author: Ian.M
author_rank: Super Contributor
timestamp: February 07, 2021, 09:59:53 am
content: That's a PITA. To implement a circuit on the target board to force bootloader entry without physical USB disconnection you'd need a PMOS transistor in the Vcc feed to the CH55x MCU, with its gate pulled low, and a circuit to pulse the gate high to cut the power for long enough when the Prog button (that pulls down the bootloader sense pin) is initially pressed. There are more ways of implementing that than you can shake a stick at - it very much depends on what spare gates, OPAMPs etc. you already have available.