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 #144

Closed
wants to merge 11 commits into from
Closed

USB support #144

wants to merge 11 commits into from

Conversation

japaric
Copy link
Contributor

@japaric japaric commented May 11, 2020

this PR builds on top of @jonas-schievink PR (#133)

I have managed to get a CDC ACM (using the usbd-serial crate) device enumerated and got some output out from it using the following program (snippet):

    loop {
        if !usb_dev.poll(&mut [&mut serial]) {
            continue;
        }

        if usb_dev.state() == UsbDeviceState::Configured {
            if once {
                serial.write(b"Hello, world!\n").unwrap();
                serial.flush().unwrap();

                once = false;
            }
        }
    }
$ cat /dev/ttyACM1
Hello, world!

(don't forget to send a newline or cat won't print anything)

However, I'm not getting reliable enumeration (*). I still need to dig deeper into that issue but would appreciate other people testing out this branch.

(*) though this may be mainly caused by how I'm terminating my embedded application: I'm halting the device without first disconnecting it from the USB bus; this seems to make the host USB controller very sad (it power cycles the USB bus a few times and never gets an answer from the device (because it's halted))

P.S. this branch depends on this Jonas' fork of usbd-device (which handles the nrf52 quirk of handling SET_ADDRESS requests entirely in hardware). Use the following patch before you try out this branch:

[patch.crates-io.usb-device]
git = "https://github.com/jonas-schievink/usb-device.git"
branch = "inhibit-setaddr-resp"

@Disasm
Copy link
Contributor

Disasm commented Jul 8, 2020

We have a test repo with a few tests that you can port and run on your hardware: https://github.com/Disasm/stm32-usbd-tests

@Disasm
Copy link
Contributor

Disasm commented Aug 4, 2020

For some reason, this driver doesn't work with the default EP0 size (8 bytes). Also a serial loopback example (based on https://github.com/Disasm/usb-otg-workspace/blob/master/example-f429zi-board/examples/serial.rs#L63-L85) fails to pass stress-testing.

@valpackett
Copy link

Rebasing the usb-device quirk onto the current (0.2.7) version, looks like rust-embedded-community/usb-device@7509c77 breaks device enumeration, I've had to revert that commit to make it work.


unsafe {
if ep_addr.index() == 0 {
regs.tasks_ep0stall.write(|w| w.tasks_ep0stall().set_bit());

Choose a reason for hiding this comment

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

Oh.

                    regs.tasks_ep0stall.write(|w| if stalled { w.tasks_ep0stall().set_bit() } else { w.tasks_ep0stall().clear_bit() });

Copy link
Member

Choose a reason for hiding this comment

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

I went with:

  regs.tasks_ep0stall.write(|w| w.tasks_ep0stall().bit(stalled));

@wez
Copy link
Member

wez commented Feb 14, 2021

@nrf-rs/nrf52 I've rebased this and plan to push this PR + my local fixup diff to close out this PR.

I have a few "Particle Xenon" boards with 52840's on them, as well as that weird MDK thing that I previously added a bsp for in this org, so I'm able to test this and confirmed that the device enumerates and responds:

[72570.386287] usb 3-3.4.4.2: New USB device strings: Mfr=0, Product=2, SerialNumber=0
[72570.386289] usb 3-3.4.4.2: Product: nRF52840 Serial Port Demo
[72570.472123] cdc_acm 3-3.4.4.2:1.0: ttyACM0: USB ACM device
[72570.472567] usbcore: registered new interface driver cdc_acm
[72570.472569] cdc_acm: USB Abstract Control Model driver for USB modems and ISDN adapters
$ sudo cat /dev/ttyACM0
Hello, world!
^C

@jonas-schievink
Copy link
Contributor

Awesome! Happy to take a look.

@wez
Copy link
Member

wez commented Feb 14, 2021

My fixup diff on top of this is minor; I'll just push it and if you spot something I'm around to act on it!

@wez wez closed this in 8a5ee04 Feb 14, 2021
@jonas-schievink
Copy link
Contributor

Please wait for CI to pass before pushing to master

@wez
Copy link
Member

wez commented Feb 14, 2021

Too late... but I'm running those tests locally and fixing up now :)

@Disasm
Copy link
Contributor

Disasm commented Feb 14, 2021

I'm going to run test_class as well as the serial benchmark soon

wez added a commit that referenced this pull request Feb 14, 2021
@Disasm
Copy link
Contributor

Disasm commented Feb 14, 2021

Tested, the behavior is the same as mentioned in #144 (comment)

Disasm pushed a commit to Disasm/nrf-hal that referenced this pull request Feb 17, 2021
Fixes compilation by pointing to current versions and takes in
@unrelentingtech's fork of usb-device and suggestion in
nrf-rs#144 (review)

I folded in the hello world portion from japaric's PR summary text.

refs: rust-embedded-community/usb-device#51

closes: nrf-rs#144
@Disasm Disasm mentioned this pull request Feb 17, 2021
Disasm pushed a commit to Disasm/nrf-hal that referenced this pull request Feb 17, 2021
fnafnio pushed a commit to fnafnio/nrf-hal that referenced this pull request May 12, 2021
Fixes compilation by pointing to current versions and takes in
@unrelentingtech's fork of usb-device and suggestion in
nrf-rs#144 (review)

I folded in the hello world portion from japaric's PR summary text.

refs: rust-embedded-community/usb-device#51

closes: nrf-rs#144
fnafnio pushed a commit to fnafnio/nrf-hal that referenced this pull request May 12, 2021
Dirbaio pushed a commit to nrf-rs/nrf-usbd that referenced this pull request Jun 10, 2021
Fixes compilation by pointing to current versions and takes in
@unrelentingtech's fork of usb-device and suggestion in
nrf-rs/nrf-hal#144 (review)

I folded in the hello world portion from japaric's PR summary text.

refs: rust-embedded-community/usb-device#51

closes: nrf-rs/nrf-hal#144
Dirbaio pushed a commit to nrf-rs/nrf-usbd that referenced this pull request Jun 10, 2021
Fixes compilation by pointing to current versions and takes in
@unrelentingtech's fork of usb-device and suggestion in
nrf-rs/nrf-hal#144 (review)

I folded in the hello world portion from japaric's PR summary text.

refs: rust-embedded-community/usb-device#51

closes: nrf-rs/nrf-hal#144
bors bot added a commit that referenced this pull request Jul 7, 2021
295: USB support r=Dirbaio a=Disasm

This PR is based on #144 and previous attempts.

Co-authored-by: Jonas Schievink <[email protected]>
Co-authored-by: Jorge Aparicio <[email protected]>
Co-authored-by: Wez Furlong <[email protected]>
Co-authored-by: Vadim Kaushan <[email protected]>
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.

5 participants