From a10fffdac6e429491934cb2fd9f754e6273aa4ad Mon Sep 17 00:00:00 2001 From: Wez Furlong Date: Wed, 12 May 2021 07:52:17 +0200 Subject: [PATCH] Rebase #144, formerly #133 to pull in USB for nrf52480 Fixes compilation by pointing to current versions and takes in @unrelentingtech's fork of usb-device and suggestion in https://github.com/nrf-rs/nrf-hal/pull/144#pullrequestreview-574865733 I folded in the hello world portion from japaric's PR summary text. refs: https://github.com/mvirkkunen/usb-device/pull/51 closes: https://github.com/nrf-rs/nrf-hal/pull/144 --- Cargo.toml | 2 +- examples/usb/Cargo.toml | 5 +++-- examples/usb/src/main.rs | 6 ++++++ nrf-hal-common/Cargo.toml | 2 +- nrf-hal-common/src/usbd/mod.rs | 7 +++---- 5 files changed, 14 insertions(+), 8 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index fb1560aa..b63b6d5a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -24,5 +24,5 @@ lto = true opt-level = "s" [patch.crates-io.usb-device] -git = "https://github.com/jonas-schievink/usb-device.git" +git = "https://github.com/unrelentingtech/usb-device.git" branch = "inhibit-setaddr-resp" diff --git a/examples/usb/Cargo.toml b/examples/usb/Cargo.toml index 7573444b..14aa144c 100644 --- a/examples/usb/Cargo.toml +++ b/examples/usb/Cargo.toml @@ -10,9 +10,10 @@ cortex-m-rt = "0.6.12" cortex-m-semihosting = "0.3.5" panic-semihosting = "0.5.3" nrf52840-pac = "0.9.0" -usb-device = "0.2.5" +usb-device = "0.2.7" usbd-serial = "0.1.0" [dependencies.nrf52840-hal] -version = "0.10.0" +version = "0.12.0" path = "../../nrf52840-hal" + diff --git a/examples/usb/src/main.rs b/examples/usb/src/main.rs index d0b71532..2b847639 100644 --- a/examples/usb/src/main.rs +++ b/examples/usb/src/main.rs @@ -51,6 +51,7 @@ fn main() -> ! { let p1 = p1::Parts::new(periph.P1); let mut led = p0.p0_23.into_push_pull_output(Level::High); + let btn = p1.p1_00.into_pullup_input(); while btn.is_high().unwrap() {} @@ -79,6 +80,11 @@ fn main() -> ! { if new_state != state { hprintln!("{:?} {:#x}", new_state, usb_dev.bus().device_address()).ok(); state = new_state; + + if state == UsbDeviceState::Configured { + serial.write(b"Hello, world!\n").unwrap(); + serial.flush().unwrap(); + } } } } diff --git a/nrf-hal-common/Cargo.toml b/nrf-hal-common/Cargo.toml index 53cbfdae..1187b3f9 100644 --- a/nrf-hal-common/Cargo.toml +++ b/nrf-hal-common/Cargo.toml @@ -39,7 +39,7 @@ optional = true version = "0.9.0" [dependencies.usb-device] -version = "0.2.5" +version = "0.2.7" optional = true [dependencies.nrf52810-pac] diff --git a/nrf-hal-common/src/usbd/mod.rs b/nrf-hal-common/src/usbd/mod.rs index 043b15ac..ec5ac8a0 100644 --- a/nrf-hal-common/src/usbd/mod.rs +++ b/nrf-hal-common/src/usbd/mod.rs @@ -10,7 +10,7 @@ mod errata; use crate::{ clocks::{Clocks, ExternalOscillator}, - target::USBD, + pac::USBD, }; use core::sync::atomic::{compiler_fence, Ordering}; use core::{cell::Cell, mem, ptr, slice}; @@ -470,7 +470,7 @@ impl UsbBus for Usbd<'_> { // stage and must be followed by us responding with an ACK token to an OUT token // sent from the host (AKA the status stage) -- `usb-device` provides no call back // for that so we'll trigger the status stage using a shortcut - let is_short_packet = buf.len() < self.max_packet_size_0.into(); + let is_short_packet = buf.len() < self.max_packet_size_0 as usize; regs.shorts.modify(|_, w| { if is_short_packet { w.ep0datadone_ep0status().set_bit() @@ -572,7 +572,7 @@ impl UsbBus for Usbd<'_> { unsafe { if ep_addr.index() == 0 { - regs.tasks_ep0stall.write(|w| w.tasks_ep0stall().set_bit()); + regs.tasks_ep0stall.write(|w| w.tasks_ep0stall().bit(stalled)); } else { regs.epstall.write(|w| { w.ep() @@ -607,7 +607,6 @@ impl UsbBus for Usbd<'_> { errata::pre_wakeup(); regs.lowpower.write(|w| w.lowpower().force_normal()); - }); }