Skip to content

Commit

Permalink
Rebase nrf-rs#144, formerly nrf-rs#133 to pull in USB for nrf52480
Browse files Browse the repository at this point in the history
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
  • Loading branch information
wez authored and fnafnio committed May 12, 2021
1 parent bf633c3 commit a10fffd
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 8 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
5 changes: 3 additions & 2 deletions examples/usb/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"

6 changes: 6 additions & 0 deletions examples/usb/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {}

Expand Down Expand Up @@ -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();
}
}
}
}
2 changes: 1 addition & 1 deletion nrf-hal-common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
7 changes: 3 additions & 4 deletions nrf-hal-common/src/usbd/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -607,7 +607,6 @@ impl UsbBus for Usbd<'_> {
errata::pre_wakeup();

regs.lowpower.write(|w| w.lowpower().force_normal());

});
}

Expand Down

0 comments on commit a10fffd

Please sign in to comment.