Skip to content

Commit 8a5ee04

Browse files
committed
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 #144 (review) I folded in the hello world portion from japaric's PR summary text. refs: rust-embedded-community/usb-device#51 closes: #144
1 parent 707c199 commit 8a5ee04

File tree

6 files changed

+15
-9
lines changed

6 files changed

+15
-9
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,5 @@ lto = true
2222
opt-level = "s"
2323

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

examples/usb/Cargo.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,10 @@ cortex-m-rt = "0.6.12"
1010
cortex-m-semihosting = "0.3.5"
1111
panic-semihosting = "0.5.3"
1212
nrf52840-pac = "0.9.0"
13-
usb-device = "0.2.5"
13+
usb-device = "0.2.7"
1414
usbd-serial = "0.1.0"
1515

1616
[dependencies.nrf52840-hal]
17-
version = "0.10.0"
17+
version = "0.12.0"
1818
path = "../../nrf52840-hal"
19+

examples/usb/src/main.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ fn main() -> ! {
5151
let p1 = p1::Parts::new(periph.P1);
5252

5353
let mut led = p0.p0_23.into_push_pull_output(Level::High);
54+
5455
let btn = p1.p1_00.into_pullup_input();
5556
while btn.is_high().unwrap() {}
5657

@@ -79,6 +80,11 @@ fn main() -> ! {
7980
if new_state != state {
8081
hprintln!("{:?} {:#x}", new_state, usb_dev.bus().device_address()).ok();
8182
state = new_state;
83+
84+
if state == UsbDeviceState::Configured {
85+
serial.write(b"Hello, world!\n").unwrap();
86+
serial.flush().unwrap();
87+
}
8288
}
8389
}
8490
}

nrf-hal-common/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ optional = true
3939
version = "0.9.0"
4040

4141
[dependencies.usb-device]
42-
version = "0.2.5"
42+
version = "0.2.7"
4343
optional = true
4444

4545
[dependencies.nrf52810-pac]

nrf-hal-common/src/usbd/mod.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ mod errata;
1010

1111
use crate::{
1212
clocks::{Clocks, ExternalOscillator},
13-
target::USBD,
13+
pac::USBD,
1414
};
1515
use core::sync::atomic::{compiler_fence, Ordering};
1616
use core::{cell::Cell, mem, ptr, slice};
@@ -470,7 +470,7 @@ impl UsbBus for Usbd<'_> {
470470
// stage and must be followed by us responding with an ACK token to an OUT token
471471
// sent from the host (AKA the status stage) -- `usb-device` provides no call back
472472
// for that so we'll trigger the status stage using a shortcut
473-
let is_short_packet = buf.len() < self.max_packet_size_0.into();
473+
let is_short_packet = buf.len() < self.max_packet_size_0 as usize;
474474
regs.shorts.modify(|_, w| {
475475
if is_short_packet {
476476
w.ep0datadone_ep0status().set_bit()
@@ -572,7 +572,7 @@ impl UsbBus for Usbd<'_> {
572572

573573
unsafe {
574574
if ep_addr.index() == 0 {
575-
regs.tasks_ep0stall.write(|w| w.tasks_ep0stall().set_bit());
575+
regs.tasks_ep0stall.write(|w| w.tasks_ep0stall().bit(stalled));
576576
} else {
577577
regs.epstall.write(|w| {
578578
w.ep()
@@ -607,7 +607,6 @@ impl UsbBus for Usbd<'_> {
607607
errata::pre_wakeup();
608608

609609
regs.lowpower.write(|w| w.lowpower().force_normal());
610-
611610
});
612611
}
613612

nrf52840-hal/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ nrf52840-pac = "0.9.0"
2222
[dependencies.nrf-hal-common]
2323
path = "../nrf-hal-common"
2424
default-features = false
25-
features = ["52840"]
25+
features = ["52840", "usb-device"]
2626
version = "=0.12.0"
2727

2828
[dependencies.embedded-hal]

0 commit comments

Comments
 (0)