cnlohr / rv003usb

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

detachement can be handled without any additional gpio #10

Closed jnk0le closed 9 months ago

jnk0le commented 1 year ago

A trick from f103 usb stacks.

Instead of dedicating another gpio line for attaching by 1,5K resistor, you can tie this resistor to VCC and configure D- line to output logical low for certain amount of time to detach from the bus.

This detachment must be executed at least once and finish after everthing is initialized.

cnlohr commented 1 year ago

That should certainly be documented and kept, and mentioned in the readme.

cnlohr commented 1 year ago

For actual USB devices, this is likely to be the standard way to do it. For bootloader-mode, it is unlikely we would want to do this, because user code may misconfigure the port.

xsrf commented 10 months ago

Added https://github.com/cnlohr/rv003usb/pull/38 which makes USB_DPU optional, so you can actually just hardwire D- with 1.5K to 3V3 and force D- low to re-enumerate. (edit: for the bootloader ;))

xsrf commented 9 months ago

Any ideas how long D- needs to be held low for re-enumeration? So far couldn't find anything about that in the USB specification. @jnk0le

jnk0le commented 9 months ago

typically (e.g. stm32duino) it's 10-20ms.

xsrf commented 9 months ago

typically (e.g. stm32duino) it's 10-20ms.

I actually found the reference in the USB 2.0 Spec. A disconnect is recognized after only 2.5µs of SE0 (both data lines low). See TDDIS in Table 7-13 of Universal Serial Bus Specification Revision 2.0.

So 10ms is plenty.

cnlohr commented 9 months ago

Close issue now? The PR's been merged to make PU resistor is optional.