Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

usbfs: add support for the USBFS peripheral #57

Draft
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

rmsyn
Copy link
Contributor

@rmsyn rmsyn commented Jun 6, 2023

Adds support for the USB full speed device peripheral.

Implements the Device function using the usb-device crate.

Creates a new usbfs module to allow for adding the OTG and Host functions in later work.

Depends on #56

rmsyn added 3 commits May 28, 2023 19:49
Updates cargo dependencies, and removes the deprecated `bare_metal::Nr`
trait.

The `bare_metal::Nr` is no longer present in the latest version, and all
usage in this HAL are easily replaced by directly converting the
`Interrupt` enum to a base integer type.
Adds `.option +zicsr` to `eclic-mode-hack.S` to fix a failure to
assemble with recent versions of `riscv64-unknown-elf-gcc` (e.g.
12.2.0).
Updates the precompiled `bin/gd32vf103xx-hal.a` part of the library.
Adds support for the USB full speed device peripheral.

Implements the `Device` function using the [usb-device](https://github.com/rust-embedded-community/usb-device) crate.

Creates a new `usbfs` module to allow for adding the `OTG` and `Host`
functions in later work.
Changes the main clock from `McycleDelay` to `Delay<TIMER2>`.

The C/C++ library from Gigadevice uses `TIMER2` as the USBFS timer, so
mirror that in the HAL.
Adds the relevant part of the `usb_core_init` initialization sequence
from the C/C++ GigaDevice library.
@rmsyn
Copy link
Contributor Author

rmsyn commented Jun 18, 2023

Moving this work to a draft PR.

Currently, having issues with getting the device to detect VBUS line. The device will power on when the VBUS wire is plugged directly into a 3.3V/5V power line, but not the VBUS line.

There is also a read error when the device gets detected by the host, and I still need to make the TX FIFO sizes configurable based on the type of device.

I'll continue debugging, and update the PR with fixes. Any help/advice is greatly appreciated.

@rmsyn rmsyn marked this pull request as draft June 18, 2023 05:12
@Disasm
Copy link
Member

Disasm commented Jun 18, 2023 via email

@rmsyn
Copy link
Contributor Author

rmsyn commented Jun 19, 2023

It would be nice to re-use it, but testing is needed for different chips to avoid regressions.

So, I rebased the work in #50 on the latest gd32vf103-pac, and did some minor updates to get it to work with the longan-nano USBFS example. It still doesn't work, it actually is less functional (it doesn't respond to Setup Address commands). edit: The issues I was noticing seem to be from something else in the stack.

edit: So, I think something else is the issue with my example in longan-nano. I tested against your example in https://github.com/Disasm/usb-otg-workspace, and it seems to work fine. Going to try using a full HIDClass example based on yours, see if I can actually get it to send keyboard reports to the host.

I still can't get the VBUS line to power the device. Working on getting the hardware setup to proxy the device, because the device doesn't register the vid/pid (via lsusb), and I can only get read errors/setup address errors by plugging the D+/D- lines into the wrong pins (errors via dmesg).

Added an HID example to usb-otg-workspace, but it also doesn't register as a USB device via lsusb. Tried the test-class example, but no luck there either.

It feels like I'm missing something. I am using a USB-C breakout board to connect VBUS, GND, D-, and D+ to the longan-nano's 5v, GND, PA11, and PA12 pins (alternatively trying PA9 for VBUS). Nothing produces a listing on the host...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants