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

USB Support #11

Closed
2 of 6 tasks
wez opened this issue Sep 14, 2018 · 11 comments
Closed
2 of 6 tasks

USB Support #11

wez opened this issue Sep 14, 2018 · 11 comments

Comments

@wez
Copy link
Member

wez commented Sep 14, 2018

This issue is tracking the implementation of USB.

wez added a commit that referenced this issue Sep 14, 2018
This commit is the first working enumeration of USB in rust
on the metro m0 hardware!

In order to compile, it uses an unsafely modified version of
the usb_device crate that avoids the use of missing atomics
(Refs: rust-embedded-community/usb-device#2)

I'm able to enumerate and communicate on the basic CDC implementation
borrowed from
https://github.com/mvirkkunen/stm32f103xx-usb/blob/master/examples/serial.rs
and ported to the metro_m0

Refs: #11
wez added a commit that referenced this issue Sep 14, 2018
wez added a commit that referenced this issue Sep 14, 2018
wez added a commit that referenced this issue Sep 15, 2018
This commit is the first working enumeration of USB in rust
on the metro m0 hardware!

In order to compile, it uses an unsafely modified version of
the usb_device crate that avoids the use of missing atomics
(Refs: rust-embedded-community/usb-device#2)

I'm able to enumerate and communicate on the basic CDC implementation
borrowed from
https://github.com/mvirkkunen/stm32f103xx-usb/blob/master/examples/serial.rs
and ported to the metro_m0

Refs: #11
wez added a commit that referenced this issue Sep 15, 2018
wez added a commit that referenced this issue Sep 15, 2018
wez added a commit that referenced this issue Sep 15, 2018
This commit is the first working enumeration of USB in rust
on the metro m0 hardware!

In order to compile, it uses an unsafely modified version of
the usb_device crate that avoids the use of missing atomics
(Refs: rust-embedded-community/usb-device#2)

I'm able to enumerate and communicate on the basic CDC implementation
borrowed from
https://github.com/mvirkkunen/stm32f103xx-usb/blob/master/examples/serial.rs
and ported to the metro_m0

Refs: #11
wez added a commit that referenced this issue Sep 15, 2018
wez added a commit that referenced this issue Sep 15, 2018
@zklapow
Copy link
Contributor

zklapow commented Sep 25, 2018

FWIW I spent some time getting the USB stuff to work with RTFM (which could help with eliminating the globals) but found it hard to get both the inner references (i.e. device needs a ref to the serial object) and then return those same objects from init (because the objects constructed in init did not have static lifetimes). I am sure there is some magic here that would allow RTFM to work that I am just missing though I am not sure whether RTFM counts as solving the globals issue.

@twitchyliquid64
Copy link
Contributor

I'm interested in working on this, but as a newbie to rust its best if I'm told what to do. How can I help?

@sajattack
Copy link
Member

This is one of those thing's that's left over from when @wez was running the project and frankly I'm scared to touch it lol.

@wez
Copy link
Member Author

wez commented Sep 15, 2019

I've been a bit too busy to pick this up in a while. Things have matured a bit more in the upstream usb-device crate so what I think needs to be done in this one now is:

With that done, we'll have a relatively low level support for USB on this class of devices and can consider actually enabling that code when publishing to crates.io, but there is still more to be done to make practical USB device implementations:

  • USB HID support (near and dear to my heart for keyboards)
  • USB storage device support to expose eg: on-board SPI based flash storage, or perhaps UF2 bootloader

I see these as requiring some work in the upstream usb device crate with appropriate atsamd-specific support happening in this crate.

There's also a distinction between low-level support (eg: it basically works) and ergonomic high-level support (eg: there's a nice way to respond to USB HID events and embed support in a consuming application crate).

Beyond the bus implementation in this crate, most of the work to be done is generic USB stuff that should happen in the usb-device project.

@twitchyliquid64
Copy link
Contributor

I'll take a look at updating the samd21 crate, but I don't have hardware so it will need someone else to test.

I'll also try and get it working for samd51, which I do have hardware for.

@twitchyliquid64
Copy link
Contributor

Looking at the samd21 code, it looks very similar to what is required for samd51. I expect there's a good amount we can put in the common crate.

@twitchyliquid64
Copy link
Contributor

This is slowly coming along here. Some notes/changes for comment:

  • Instead of only exposing an implementation of the usb_device::bus::UsbBus device, I'm going to expose a lower-level (no state, no memory management) API UsbController, which the UsbBus implementation will be built off.
  • I'm refactoring the ep! macro to collect all the registers for a given endpoint into a single structure, EndpointRegs, which will provide a nicer internal API over mutating the state of the endpoint registers.
  • Aside from HAL layers, move away from using the term Bank to describe one endpoint in an endpoint pair, as I couldnt find any reference to it outside of datasheets.
  • I'm using a single lifetime across all objects from UsbController downwards, and instantiating them all at the same time. This allows us to avoid Ref* and Mutex boxing.

@twitchyliquid64
Copy link
Contributor

Heya @wez, how did you get the dbgprint! macro to dance your tune?

I made the mistake of writing the samd51 driver all at once, so it attaches but doesnt enumerate. I'm thinking it would be nice to have a printf out a SERCOM UART, but if thats something youve already done I'll gladly copypasta :)

@BenBergman
Copy link
Contributor

@twitchyliquid64 Did you make any progress on the samd21 port? I've got some devices I'd be willing to test with.

@twitchyliquid64
Copy link
Contributor

@BenBergman no - haven't ported samd21 USB support over to the 0.3 version of usb-device. The original code (which ran from an earlier version) should still be usable.

In terms of working on the USB peripheral, I've been side-tracked by other projects as of late, but hope to get back to this + fixing the other bug soon.

@BenBergman
Copy link
Contributor

I tried compiling the Metro-M0 usb-serial example but it is failing to compile for me, so I'm guessing some other change broke something. I poked at it a bit but low level USB is a bit beyond me and the limited time I have to focus on it.

Let me know when you get back to it and I can test on a few Adafruit M0 boards I have lying around.

kaizensparc pushed a commit to kaizensparc/atsamd that referenced this issue Dec 24, 2021
This commit is the first working enumeration of USB in rust
on the metro m0 hardware!

In order to compile, it uses an unsafely modified version of
the usb_device crate that avoids the use of missing atomics
(Refs: rust-embedded-community/usb-device#2)

I'm able to enumerate and communicate on the basic CDC implementation
borrowed from
https://github.com/mvirkkunen/stm32f103xx-usb/blob/master/examples/serial.rs
and ported to the metro_m0

Refs: atsamd-rs#11
kaizensparc pushed a commit to kaizensparc/atsamd that referenced this issue Dec 24, 2021
kaizensparc pushed a commit to kaizensparc/atsamd that referenced this issue Dec 24, 2021
FriederHannenheim pushed a commit to FriederHannenheim/atsamd that referenced this issue May 22, 2024
* New interrupt binding scheme.
* Add multiple interrupt sources to single handler
* Fix examples
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

No branches or pull requests

5 participants