Skip to content

Commit 291d6f8

Browse files
bors[bot]Disasm
andauthored
Merge #320
320: Update USB driver r=burrbull a=Disasm Co-authored-by: Vadim Kaushan <admin@disasm.info>
2 parents 49f7505 + 64741b7 commit 291d6f8

File tree

7 files changed

+23
-26
lines changed

7 files changed

+23
-26
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
99

1010
### Breaking changes
1111

12+
- Bump `stm32-usbd` dependency (`0.6.0`)
1213
- Use bit-banding for Peripheral enable/reset.
1314
Don't require APBs in initializers.
1415
- Rename `gpio::Edge::{RISING, FALLING, RISING_FALLING}` to `Rising`, `Falling`, `RisingFalling`, respectively
@@ -37,6 +38,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
3738

3839
### Changed
3940

41+
- USB driver is now enabled by default for all devices supporting it
4042
- Updated `bxcan` dependency
4143
- Change internal implementation of pins using const generics
4244
- Use `cortex-m-rtic` instead of `cortex-m-rtfm` in the examples

Cargo.toml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ edition = "2018"
1212
version = "0.7.0"
1313

1414
[package.metadata.docs.rs]
15-
features = ["stm32f103", "rt", "stm32-usbd"]
15+
features = ["stm32f103", "rt"]
1616
default-target = "x86_64-unknown-linux-gnu"
1717

1818
[dependencies]
@@ -36,8 +36,7 @@ version = "0.2.3"
3636
features = ["unproven"]
3737

3838
[dependencies.stm32-usbd]
39-
version = "0.5.0"
40-
features = ["ram_access_1x16"]
39+
version = "0.6.0"
4140
optional = true
4241

4342
[dev-dependencies]
@@ -79,7 +78,7 @@ doc = []
7978
rt = ["stm32f1/rt"]
8079
stm32f100 = ["stm32f1/stm32f100", "device-selected"]
8180
stm32f101 = ["stm32f1/stm32f101", "device-selected"]
82-
stm32f103 = ["stm32f1/stm32f103", "device-selected", "has-can"]
81+
stm32f103 = ["stm32f1/stm32f103", "device-selected", "has-can", "stm32-usbd"]
8382
stm32f105 = ["stm32f1/stm32f107", "device-selected", "connectivity"]
8483
stm32f107 = ["stm32f1/stm32f107", "device-selected", "connectivity"]
8584

examples/usb_serial.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ extern crate panic_semihosting;
1414
use cortex_m::asm::delay;
1515
use cortex_m_rt::entry;
1616
use stm32f1xx_hal::usb::{Peripheral, UsbBus};
17-
use stm32f1xx_hal::{prelude::*, stm32};
17+
use stm32f1xx_hal::{pac, prelude::*};
1818
use usb_device::prelude::*;
1919
use usbd_serial::{SerialPort, USB_CLASS_CDC};
2020

@@ -23,7 +23,7 @@ fn main() -> ! {
2323
let dp = pac::Peripherals::take().unwrap();
2424

2525
let mut flash = dp.FLASH.constrain();
26-
let mut rcc = dp.RCC.constrain();
26+
let rcc = dp.RCC.constrain();
2727

2828
let clocks = rcc
2929
.cfgr

examples/usb_serial_interrupt.rs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ extern crate panic_semihosting;
77

88
use cortex_m::asm::{delay, wfi};
99
use cortex_m_rt::entry;
10-
use stm32f1xx_hal::pac::{interrupt, Interrupt};
10+
use stm32f1xx_hal::pac::{self, interrupt, Interrupt, NVIC};
11+
use stm32f1xx_hal::prelude::*;
1112
use stm32f1xx_hal::usb::{Peripheral, UsbBus, UsbBusType};
12-
use stm32f1xx_hal::{prelude::*, stm32};
1313
use usb_device::{bus::UsbBusAllocator, prelude::*};
1414
use usbd_serial::{SerialPort, USB_CLASS_CDC};
1515

@@ -19,11 +19,10 @@ static mut USB_DEVICE: Option<UsbDevice<UsbBusType>> = None;
1919

2020
#[entry]
2121
fn main() -> ! {
22-
let p = cortex_m::Peripherals::take().unwrap();
2322
let dp = pac::Peripherals::take().unwrap();
2423

2524
let mut flash = dp.FLASH.constrain();
26-
let mut rcc = dp.RCC.constrain();
25+
let rcc = dp.RCC.constrain();
2726

2827
let clocks = rcc
2928
.cfgr
@@ -71,10 +70,10 @@ fn main() -> ! {
7170
USB_DEVICE = Some(usb_dev);
7271
}
7372

74-
let mut nvic = p.NVIC;
75-
76-
nvic.enable(Interrupt::USB_HP_CAN_TX);
77-
nvic.enable(Interrupt::USB_LP_CAN_RX0);
73+
unsafe {
74+
NVIC::unmask(Interrupt::USB_HP_CAN_TX);
75+
NVIC::unmask(Interrupt::USB_LP_CAN_RX0);
76+
}
7877

7978
loop {
8079
wfi();

examples/usb_serial_rtic.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ const APP: () = {
2626
static mut USB_BUS: Option<bus::UsbBusAllocator<UsbBusType>> = None;
2727

2828
let mut flash = cx.device.FLASH.constrain();
29-
let mut rcc = cx.device.RCC.constrain();
29+
let rcc = cx.device.RCC.constrain();
3030

3131
let clocks = rcc
3232
.cfgr

src/lib.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -180,10 +180,7 @@ pub mod spi;
180180
pub mod time;
181181
#[cfg(feature = "device-selected")]
182182
pub mod timer;
183-
#[cfg(all(
184-
feature = "stm32-usbd",
185-
any(feature = "stm32f102", feature = "stm32f103")
186-
))]
183+
#[cfg(all(feature = "device-selected", feature = "stm32-usbd"))]
187184
pub mod usb;
188185
#[cfg(feature = "device-selected")]
189186
pub mod watchdog;

src/usb.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
//! for usage examples.
66
77
use crate::pac::{RCC, USB};
8+
use crate::rcc::{Enable, Reset};
89
use stm32_usbd::UsbPeripheral;
910

1011
use crate::gpio::gpioa::{PA11, PA12};
@@ -24,18 +25,17 @@ unsafe impl UsbPeripheral for Peripheral {
2425
const DP_PULL_UP_FEATURE: bool = false;
2526
const EP_MEMORY: *const () = 0x4000_6000 as _;
2627
const EP_MEMORY_SIZE: usize = 512;
28+
const EP_MEMORY_ACCESS_2X16: bool = false;
2729

2830
fn enable() {
29-
let rcc = unsafe { (&*RCC::ptr()) };
31+
unsafe {
32+
let rcc = &*RCC::ptr();
3033

31-
cortex_m::interrupt::free(|_| {
3234
// Enable USB peripheral
33-
rcc.apb1enr.modify(|_, w| w.usben().set_bit());
34-
35+
USB::enable(rcc);
3536
// Reset USB peripheral
36-
rcc.apb1rstr.modify(|_, w| w.usbrst().set_bit());
37-
rcc.apb1rstr.modify(|_, w| w.usbrst().clear_bit());
38-
});
37+
USB::reset(rcc);
38+
}
3939
}
4040

4141
fn startup_delay() {

0 commit comments

Comments
 (0)