cnlohr / rv003usb

CH32V003 RISC-V Pure Software USB Controller
MIT License
459 stars 47 forks source link

Proper connection D-, D+ to CH32V003? #9

Closed RandoSY closed 1 year ago

RandoSY commented 1 year ago

I've been following along, and have successfully built both the ESP32S2 programmer out of an old S2 Mini D1, and also taken a new WCHLinkE, used Zadig to load the proper lib-usb driver, and was delighted to see the tool chain was able to flash the latest and greatest rv000usb firmware to an inexpensive CH32V003 WCHDEV board.

I took a look at the header file and saw these pin definitions:

// Port D.3 = D+ // Port D.4 = D- // Port D.5 = DPU

CH32V003-development-board

I was wondering if I can just add a connection to the proper pins on the dev board correctly via D+ and D- from a breakout cable or do I need to make some allowance for voltage levels on the USB interface?

4448-01

RandoSY commented 1 year ago

I did find some good info ... seems relevant.

https://www.beyondlogic.org/usbnutshell/usb2.shtml

Low speed

52f3c319ce395f904a8b4569

RandoSY commented 1 year ago

Taking a look at the schematic in Kicad for the development board featured in the Youtube video, implementing the SW only USB port ... we see places for resistors on the D-, and D+ lines but these are listed as "NP" (not populated).

Not sure exactly what the DPU signal is for, debug possible, it does tap off of a voltage divider (R1 and R5). Ideas?

Not Populated

cnlohr commented 1 year ago

DPU is connected, in series with a 1.5k resistor to D- in order to trigger host-detect of the USB device.

mengstr commented 1 year ago

In the Fritzing "schematic" there are two 15K resistors that pulls both D-lines weakly to the ground. Those are already a part of the host computer and/or hub, so they should not be included in the USB device.

Usually there are low ohm (68 ohm?) resistors in series with D+ and D- on the USB device. Which I guess have a twofold purpose. They will reduce ringing/reflections on the lines a bit, and as an additional bonus it will prevent bad things happening if both the host and device starts outputting data at the same time. (The latter thing should only happen if the firmware is buggy).

cnlohr commented 1 year ago

I've used a lot of these, and I typically use ~33 or ~47.

But yeah, they are def a good idea to add!

mengstr commented 1 year ago

I played around with V-USB for a bit last week on an Arduino mini which I didn't bother to convert to 3.3v. Nor did I add any series resistors or Zeners on the data lines. So straight 5 volts out on the USB bus.

Back in the olden days the USB spec did have a requirement for 5-volt tolerance on the data lines in case of a short in the cabe. But that requirement was dropped in later revisions.

To be on the safe side I connected the device to an old el-cheapo hub which was connected to a USB-A to USB-C hub which I connected to my Mac. Worked like a charm - I think. I get a 1 ms long "error package" randomly every 500 to 5000ms when it's just sitting there idling. The error package is both lines toggling at 1.5MHz just as something is NRZI encoding a continuous string of zeros.

cnlohr commented 1 year ago

I've updated the section of the readme here: https://github.com/cnlohr/rv003usb#it-requires-very-little-hardware