cnlohr / rv003usb

CH32V003 RISC-V Pure Software USB Controller
MIT License
436 stars 43 forks source link

Windows support for bootloader #34

Closed xsrf closed 8 months ago

xsrf commented 8 months ago

Adds windows support for the bootloader by fixing the USB and HID descriptors to proper values and adjusting end of scratchpad transfer detection.

Other than Linux, Windows will not allow any communication with a USB device that does not exactly follow the specs and matches USB descriptors. The original USB descriptor advertises a wMaxPacketSize of 64 which is invalid for low speed USB devices, causing enumeration to fail on many host controllers. The maximum allowed for low speed devices is 8 Bytes. The HID descriptor had a wrong Report Count and was missing a Report Size, resulting in an undefined or zero length of data it would accept.

Also added make_win.bat to build and flash the bootloader, as the make-file did not work properly for me on windows.

Fixes issues #21 and #24.

xsrf commented 8 months ago

@cnlohr I tried the bootloader also on Debian Linux and minichlink uploads fine, but ends with errors when the chip is rebooted:

$ sudo ./minichlink -w neo_blue.bin flash -b
Found B003Fun Bootloader
Halting Boot Countdown
Interface Setup
Image written.
Booting
ioctl (GFEATURE): Broken pipe
ioctl (GFEATURE): Broken pipe
ioctl (GFEATURE): Broken pipe
ioctl (GFEATURE): Broken pipe
ioctl (GFEATURE): Broken pipe
ioctl (GFEATURE): Broken pipe
ioctl (GFEATURE): Broken pipe
ioctl (GFEATURE): Broken pipe
ioctl (GFEATURE): Broken pipe
ioctl (GFEATURE): Broken pipe
ioctl (GFEATURE): Broken pipe
ioctl (GFEATURE): Broken pipe

I guess that's fine though?

cnlohr commented 8 months ago

Unless the device has support for USB, that is exactly what it should do.

This is AMAZING. Thank you so much @xsrf

cnlohr commented 8 months ago

Any chance you could be interested to join our discord? https://discord.gg/JsK7Hhfeyt