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

feat(otgfs): Implement OTG_FS USB Driver #51

Merged
merged 7 commits into from
Oct 29, 2024
Merged

Conversation

Codetector1374
Copy link
Member

The primary purpose of this change is to introduce an initial
implementation of the USB OTG FS device driver. Although this should
also applie to other SKUs that have the USB FS (without OTG) but those
are currently untested due to the lack of said hardware for testing.

In the process of implementing support for USB, we noticed that the WFI
instruction in the Qingke IP has significant flaws causing the USB
peripheral unable to access memory correctly while the CPU is under WFI.
The exact reason behind this is unclear, but a workaround has been put
inplace by using a new executor we added to embassy named arch-spin
which avoids the use of WFI instruction altogether.

Also there were several updates to the peripheral access crate (PAC) to
ensure the USB driver code is as readable as possible. The update may
have not been applied to all device families, especially those using
USB_FS instead of having the full OTG peripheral.

The code has been tested on CH32V307 and CH32V305 with the following
applications:

  • USB DFU: mostly to exercise usb control transfer
  • USB HID: mostly to exercise usb interrupt transfer

We also provided a simple USB DFU example in the examples/ch32v307
directory for those who want to just quickly verify any functionalities.

@Codetector1374
Copy link
Member Author

Ideally this should address some of the concern in #40 as this will now provide a USB_FS example in examples/ch32v307/usbfs_dfu.rs

@Codetector1374
Copy link
Member Author

Looks like there is a few things failing because some metapac updates aren't done correctly yet. Let me address those soon and get this in a clean state.

@Codetector1374
Copy link
Member Author

Test should pass once ch32-rs/ch32-data#9 is merged and I will update the dependency commit hash.

Codetector1374 and others added 5 commits October 28, 2024 22:49
The primary purpose of this change is to introduce an initial
implementation of the USB OTG FS device driver. Although this should
also applie to other SKUs that have the USB FS (without OTG) but those
are currently untested due to the lack of said hardware for testing.

In the process of implementing support for USB, we noticed that the WFI
instruction in the Qingke IP has significant flaws causing the USB
peripheral unable to access memory correctly while the CPU is under WFI.
The exact reason behind this is unclear, but a workaround has been put
inplace by using a new executor we added to embassy named `arch-spin`
which avoids the use of WFI instruction altogether.

Also there were several updates to the peripheral access crate (PAC) to
ensure the USB driver code is as readable as possible. The update may
have not been applied to all device families, especially those using
USB_FS instead of having the full OTG peripheral.

The code has been tested on CH32V307 and CH32V305 with the following
applications:
- USB DFU: mostly to exercise usb control transfer
- USB HID: mostly to exercise usb interrupt transfer

We will also provide a simple USB DFU example in the `examples/ch32v307`
directory for those who want to just quickly verify any functionalities.

Co-authored-by: Dummyc0m <[email protected]>
Co-authored-by: Codetector <[email protected]>
Looks like there will be more features than chip families so looks like
it would make more sense to have the table be transposed so on a normal
monitor it would be easier to read.
This patch removes the defmt feature from ch32-hal in the example.
- Using defmt requires that special linker script setup, and it is not
present
- I also don't believe that these simple examples should depend on defmt
anyways, especially that we can't do defmt over rtt currently.
@Codetector1374 Codetector1374 marked this pull request as ready for review October 29, 2024 05:52
@Codetector1374
Copy link
Member Author

Cool now everything should be fixed :) perfect

Copy link
Contributor

@andelf andelf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excellent work on implementing the USB driver. Let's ship this!

@andelf andelf merged commit c81d2db into ch32-rs:main Oct 29, 2024
1 check passed
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.

3 participants