EEVblog Electronics Community Forum
Electronics => Beginners => Topic started by: fabiodl on January 30, 2021, 03:04:15 am
-
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?
-
Your question needs to be reworded. Run on sentences and unclear descriptions won't get useful answers.
-
USB power contacts are longer for a reason.
Disconnecting + only should be quite safe.
-
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.
-
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.
That 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.
-
The CH559 microcontroller requires to hold a pin down while connecting to the usb (probably when receiving power) to enter in program mode.
The 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).
-
That 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.
Thank you, I wonder how are the D+/D- connected? it appears they are constantly connected, even when VBUS is disconnected.
The 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).
Thank you, that is neat. I just saw a similar trick here (https://github.com/atc1441/CH559sdccUSBHost/blob/master/uart.c)
Since I am spinning a dev board,I'd like to have some hardware solution as well.
-
That 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.
Thank you, I wonder how are the D+/D- connected? it appears they are constantly connected, even when VBUS is disconnected....
That 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.
-
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 this CH559 dev board (https://www.electrodragon.com/product/ch559-mini-dev-board-ch55x-series/) has 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.
-
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.
-
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) [here] (http://sdphca.ucsd.edu/lab_equip_manuals/usb_20.pdf)
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.
-
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/-2EXj5G5MkE
Update: This might be a better teardown video:
https://youtu.be/4RfMiyjQ12s
-
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.
-
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 this CH559 dev board (https://www.electrodragon.com/product/ch559-mini-dev-board-ch55x-series/) has 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.
Unfortunately 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.
-
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.