Skip to content

Add USBHost #4321

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

Draft
wants to merge 127 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
127 commits
Select commit Hold shift + click to select a range
35e9187
Add interrupt/isochron scheduling registers
Aug 15, 2024
a64f210
Add helper for framelistlen
Aug 16, 2024
fcddc80
Add doping register
Aug 18, 2024
094e641
Describe Hcdma reg, add HcdmaB & split hctsiz->xfersiz for interrupt/…
Aug 19, 2024
2bee542
Fix hcmda reg definition
Aug 19, 2024
d33f48e
Add more regs
Sep 6, 2024
b00002b
Add descriptor DMA setting & fix perschedena
Sep 9, 2024
1dafb65
Add frame interval dynamic loading ctl
Sep 9, 2024
219990e
Add frame list addr register
Sep 16, 2024
5bdc2da
Fix perschena mutability & fifo no-op
Sep 16, 2024
97f3db0
Restore product_id W without no-op
Sep 16, 2024
37ceaee
Improve docs & remove unnecessary unsafe
Sep 18, 2024
3062a33
Create initial USB Host driver
ijager Jul 24, 2024
2a2fbd1
Create usb_host HAL driver module
ijager Aug 9, 2024
9bf83e8
Make set_address async and wait for completion
ijager Aug 9, 2024
d821b14
Implement basic request_out api
ijager Aug 13, 2024
d855356
Implement basic out_request for requesting descriptor
ijager Aug 13, 2024
f389af4
Use proper status flaxs for detecting finisheed transactions
ijager Aug 13, 2024
5dac31e
Implement multi packet receiving
ijager Aug 14, 2024
e58e09d
Implement Endpoint0 change max_oacket_size and realloc
ijager Aug 19, 2024
12fcb45
Add USBHost Trait to embassy-usb-driver crate
ijager Aug 21, 2024
4c82c02
Implement Read for non-control endpoints
ijager Aug 28, 2024
07ea49d
Remove debug prints
ijager Aug 29, 2024
5a41223
Reuse channel write/read for control transfers
ijager Sep 3, 2024
aa5373e
Disable channels on error
ijager Sep 3, 2024
f25cc52
Make usb_host available for usb_v4 peripherals
ijager Sep 3, 2024
2e7e459
Add USB Host implementation and example for stm32g0
ijager Sep 3, 2024
6524910
Add docstrings
ijager Sep 4, 2024
0dc282b
Add comment about NUCLE0-G0B1RE together with X-NUCLEO-DRP1M1
ijager Sep 4, 2024
db039c1
Try fix conditional compilation for usb_host.rs
ijager Sep 5, 2024
84437f2
Use bitflags as alternative for defmt::bitflags in case no defmt feature
ijager Sep 5, 2024
f086d21
Dereive required traits on RequestType for non-rtt
ijager Sep 5, 2024
d84fd35
PoC partial usb host implementation for rp2040
nikvoid Sep 22, 2024
3996604
usb-host refactor, currently errors with rx timeout
nikvoid Sep 27, 2024
6862613
remove various leftovers
nikvoid Sep 28, 2024
5b4824a
fix swapped addr and packet size args...
nikvoid Sep 28, 2024
0a64dd7
allow to acquire host control channel, remove `usbh` leftovers, fix c…
nikvoid Sep 28, 2024
81e765d
relax usb channel wrapper generics; move its methods into separate ex…
nikvoid Sep 28, 2024
a1c1b9d
include some endpoint description fields into channel
nikvoid Sep 28, 2024
0d1c9f1
fix stall on SET_CONFIGURATION
nikvoid Sep 28, 2024
fa083b0
improve channel error handling (mostly in rp2040)
nikvoid Sep 28, 2024
29c2808
disable channel interrupts on drop (rp2040)
nikvoid Sep 28, 2024
1f2b774
process device disconnects (poorly)
nikvoid Sep 28, 2024
abd397f
channel link checks; shared usb device registry
nikvoid Sep 28, 2024
3090aa9
clear available bit on channel drop
nikvoid Sep 28, 2024
0a24c90
control channel alloc shortcut
nikvoid Oct 2, 2024
c6d8ffa
usb host example with keyboard
nikvoid Oct 4, 2024
5779a0b
fix early return that would cause deadlock
nikvoid Oct 4, 2024
3398d2b
split usb-host to multiple modules
nikvoid Oct 4, 2024
c8160d2
Initial implementation of usb hub driver, currently with LS through F…
nikvoid Oct 6, 2024
c0cbfdb
send PREamble packet for interrupt endpoints (rp2040)
nikvoid Oct 7, 2024
8b348ee
Re-add handler api
Oct 7, 2024
dfa0ac3
Re-add handler api
Oct 7, 2024
ccf9d8e
Convert most of the hub to the universal handler trait
Oct 9, 2024
74fa804
Finish hub & Channel PoC
Oct 12, 2024
a5c0572
Finished trait, and optimistically half-way impl for synopsys
Nov 1, 2024
d76d3c8
Clean up and add a few docs
Nov 6, 2024
2bc3c1a
Refactor stm32 usb host hal for new traits and architecture
ijager Nov 7, 2024
aa7f28c
Implement detecting device connect and speed
ijager Nov 7, 2024
85e097f
Implement new UsbChannel for stm32-usb HAL
ijager Nov 11, 2024
4b68065
Add request_out to USBOTG host impl & fix drop bug found by @ijager
Nov 7, 2024
24c16bb
Remove completed todos
Nov 7, 2024
a3d1ae5
Compatibility
Nov 7, 2024
8ed5e1d
Add retries for post-changeaddr
Nov 8, 2024
58f9faf
Add NAK ignore (test)
Nov 8, 2024
982b21b
Reduce logging intensity for interrupt requests
Nov 8, 2024
7bdbf3c
Try fix request_in length
Nov 8, 2024
0548925
Use critical section for alloc channels
ijager Nov 11, 2024
5b73369
Ignore errors on SET_IDLE and SET_PROTOCOL
ijager Nov 11, 2024
a66bed4
Implement Drop for Channel
ijager Nov 11, 2024
ee5dc40
Make KeyStatusUpdate fields public
ijager Nov 12, 2024
77d0348
Re-add handler api
Oct 7, 2024
6c405c5
Try improve reliability
Nov 11, 2024
82ad60a
Interrupt-less
Nov 13, 2024
711f64a
Try add back interrupts, with fifo leak workaround
Nov 13, 2024
7c724fb
Fix request_in
Nov 13, 2024
793939b
Fix disconnect event
Nov 13, 2024
6c7bd79
USBOTG host cleanup
Mar 22, 2025
0ef4878
ConfigurationDescriptor/EnumerationInfo refactor to enable larger con…
Mar 27, 2025
b423c4d
Add timeout to UsbHostDriver trait & refactor descriptor parsing/enum…
Apr 1, 2025
0a5e1ef
Remove old handlers folder
Apr 1, 2025
6719ef7
Add `iter_descriptors` as proposed by @AlexCharlton & deprecate parse…
Apr 5, 2025
76d4ba4
Add PartialEq to EndpointDescriptor & make StringIndex pub
Apr 5, 2025
01ab8da
Fix `get_configuration` (credit to @AlexCharlton)
Apr 5, 2025
53bd2e0
Compile with log
AlexCharlton Apr 4, 2025
e829627
Use macro to prevent code repetition
lynxD Apr 6, 2025
9e79c47
examples/rp: Allign internal crate versions
lynxD Apr 4, 2025
1f0028f
Revert "Compile with log"
AlexCharlton Apr 4, 2025
249c2bb
embassy_rp: Add missing use-s
lynxD Apr 4, 2025
9ec439d
embassy_rp: rm unused use-s
lynxD Apr 4, 2025
668cca3
embassy_rp: rm duplcated code
lynxD Apr 4, 2025
7bc5e29
embassy-rp: Allign to changed traits
lynxD Apr 7, 2025
fa96866
embassy-rp: Remove duplicate code
lynxD Apr 7, 2025
923b06f
Allign to DeviceEvent::Connected being parametrized by Speed
lynxD Apr 7, 2025
801d077
Remove unused use-s
lynxD Apr 7, 2025
9829e82
Use uppercase names for globals
lynxD Apr 7, 2025
71ff88b
Use EndpointInfo instead of EndpointDescriptor
lynxD Apr 7, 2025
fc8eff6
Correct type name in doc
lynxD Apr 7, 2025
d281357
Placeholder implementation of set_timeout to satisfy trait
lynxD Apr 7, 2025
6f05032
Fix examples/rp/.../usb_host_keyboard.rs
lynxD Apr 7, 2025
e249a18
Remove drop_channel and move to unimplemented `Drop` for Channel
Apr 9, 2025
6fa5d82
Remove usize from OUT direction requests
Apr 9, 2025
55c01d6
Add missing Synopsys registers
Apr 9, 2025
37185bb
Fix compilation
lynxD Apr 24, 2025
1bcd77b
Fix channel stall
lynxD Apr 24, 2025
75aa315
Take desc_type from argument in request_descriptor_bytes
lynxD Apr 24, 2025
de8a5eb
Fix InterfaceIterator
lynxD Apr 30, 2025
6c36022
Remove depricated usb descripor parsing functions
lynxD May 3, 2025
834edc0
Add empty set_timeout implementation
lynxD May 3, 2025
add2d2b
Fix example compilation
lynxD May 3, 2025
c1b5e1e
Remove useless comment
lynxD May 3, 2025
e9b6341
Remove unused gpio from example
lynxD May 3, 2025
adeeca6
Don't use embassy-usb-driver directly
lynxD May 3, 2025
eded793
Don't use embassy-usb-driver directly
lynxD May 3, 2025
dab3268
Make example name the same as for rp
lynxD May 3, 2025
d06be7e
Refactor
lynxD May 3, 2025
9f5eda0
Don't use embassy-usb-driver symbold directly
lynxD May 3, 2025
a1ad8e3
Remove unused import
lynxD May 3, 2025
774e4fb
Add docstrings
lynxD May 3, 2025
eb6c314
cargo fmt
lynxD May 3, 2025
4179aba
Add some missing docstrings
lynxD May 6, 2025
c5e713c
spellcheck
lynxD Jun 4, 2025
9a72d75
Shorten docstring
lynxD Jun 4, 2025
3e8cc4e
Fix after rebase
lynxD Jun 18, 2025
70df1ca
cargo fmt
lynxD Jun 18, 2025
209d8cc
Fix stm32 after rebase
lynxD Jun 19, 2025
ce948c2
cargo fmt
lynxD Jun 19, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 6 additions & 51 deletions embassy-rp/src/usb.rs → embassy-rp/src/usb/device.rs
Original file line number Diff line number Diff line change
@@ -1,44 +1,19 @@
//! USB driver.
use core::future::poll_fn;
use core::marker::PhantomData;
use core::slice;
use core::sync::atomic::{compiler_fence, Ordering};
use core::task::Poll;

use atomic_polyfill::{compiler_fence, Ordering};
use embassy_hal_internal::PeripheralType;
use embassy_sync::waitqueue::AtomicWaker;
use embassy_usb_driver as driver;
use embassy_usb_driver::{
Direction, EndpointAddress, EndpointAllocError, EndpointError, EndpointInfo, EndpointType, Event, Unsupported,
};

use super::{Dir, In, Instance, Out};
use crate::interrupt::typelevel::{Binding, Interrupt};
use crate::{interrupt, pac, peripherals, Peri, RegExt};

trait SealedInstance {
fn regs() -> crate::pac::usb::Usb;
fn dpram() -> crate::pac::usb_dpram::UsbDpram;
}

/// USB peripheral instance.
#[allow(private_bounds)]
pub trait Instance: SealedInstance + PeripheralType + 'static {
/// Interrupt for this peripheral.
type Interrupt: interrupt::typelevel::Interrupt;
}

impl crate::usb::SealedInstance for peripherals::USB {
fn regs() -> pac::usb::Usb {
pac::USB
}
fn dpram() -> crate::pac::usb_dpram::UsbDpram {
pac::USB_DPRAM
}
}

impl crate::usb::Instance for peripherals::USB {
type Interrupt = crate::interrupt::typelevel::USBCTRL_IRQ;
}
use crate::{interrupt, pac, Peri, RegExt};

const EP_COUNT: usize = 16;
const EP_MEMORY_SIZE: usize = 4096;
Expand Down Expand Up @@ -99,14 +74,14 @@ impl EndpointData {
}

/// RP2040 USB driver handle.
pub struct Driver<'d, T: Instance> {
pub struct Driver<'d, T: Instance + PeripheralType> {
phantom: PhantomData<&'d mut T>,
ep_in: [EndpointData; EP_COUNT],
ep_out: [EndpointData; EP_COUNT],
ep_mem_free: u16, // first free address in EP mem, in bytes.
}

impl<'d, T: Instance> Driver<'d, T> {
impl<'d, T: Instance + PeripheralType> Driver<'d, T> {
/// Create a new USB driver.
pub fn new(_usb: Peri<'d, T>, _irq: impl Binding<T::Interrupt, InterruptHandler<T>>) -> Self {
T::Interrupt::unpend();
Expand Down Expand Up @@ -290,7 +265,7 @@ impl<T: Instance> interrupt::typelevel::Handler<T::Interrupt> for InterruptHandl
}
}

impl<'d, T: Instance> driver::Driver<'d> for Driver<'d, T> {
impl<'d, T: Instance + PeripheralType> driver::Driver<'d> for Driver<'d, T> {
type EndpointOut = Endpoint<'d, T, Out>;
type EndpointIn = Endpoint<'d, T, In>;
type ControlPipe = ControlPipe<'d, T>;
Expand Down Expand Up @@ -491,26 +466,6 @@ impl<'d, T: Instance> driver::Bus for Bus<'d, T> {
}
}

trait Dir {
fn dir() -> Direction;
}

/// Type for In direction.
pub enum In {}
impl Dir for In {
fn dir() -> Direction {
Direction::In
}
}

/// Type for Out direction.
pub enum Out {}
impl Dir for Out {
fn dir() -> Direction {
Direction::Out
}
}

/// Endpoint for RP USB driver.
pub struct Endpoint<'d, T: Instance, D> {
_phantom: PhantomData<(&'d mut T, D)>,
Expand Down
Loading