Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
- Updated `usb-device` and `usbd-serial` to latest versions [#510]
- Rework pin remaps, fix CAN1 remap [#511]
- Rework USART remap,
- Remove unsafe code from usb_serial_rtic example [#528]

### Added

Expand Down Expand Up @@ -71,6 +72,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
[#516]: https://github.com/stm32-rs/stm32f1xx-hal/pull/516
[#520]: https://github.com/stm32-rs/stm32f1xx-hal/pull/520
[#526]: https://github.com/stm32-rs/stm32f1xx-hal/pull/526
[#528]: https://github.com/stm32-rs/stm32f1xx-hal/pull/528

## [v0.10.0] - 2022-12-12

Expand Down
34 changes: 14 additions & 20 deletions examples/usb_serial_rtic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#![no_main]
#![no_std]
#![allow(non_snake_case)]
#![deny(unsafe_code)]

use panic_semihosting as _;

Expand All @@ -22,10 +23,8 @@ mod app {
#[local]
struct Local {}

#[init]
#[init(local = [usb_bus: Option<usb_device::bus::UsbBusAllocator<UsbBusType>> = None])]
fn init(cx: init::Context) -> (Shared, Local, init::Monotonics) {
static mut USB_BUS: Option<usb_device::bus::UsbBusAllocator<UsbBusType>> = None;

let mut flash = cx.device.FLASH.constrain();
let rcc = cx.device.RCC.constrain();

Expand Down Expand Up @@ -57,23 +56,18 @@ mod app {
pin_dp: usb_dp,
};

unsafe {
USB_BUS.replace(UsbBus::new(usb));
}

let serial = usbd_serial::SerialPort::new(unsafe { USB_BUS.as_ref().unwrap() });

let usb_dev = UsbDeviceBuilder::new(
unsafe { USB_BUS.as_ref().unwrap() },
UsbVidPid(0x16c0, 0x27dd),
)
.device_class(usbd_serial::USB_CLASS_CDC)
.strings(&[StringDescriptors::default()
.manufacturer("Fake Company")
.product("Serial port")
.serial_number("TEST")])
.unwrap()
.build();
cx.local.usb_bus.replace(UsbBus::new(usb));
let usb_bus = cx.local.usb_bus.as_ref().unwrap();

let serial = usbd_serial::SerialPort::new(usb_bus);
let usb_dev = UsbDeviceBuilder::new(usb_bus, UsbVidPid(0x16c0, 0x27dd))
.device_class(usbd_serial::USB_CLASS_CDC)
.strings(&[StringDescriptors::default()
.manufacturer("Fake Company")
.product("Serial port")
.serial_number("TEST")])
.unwrap()
.build();

(Shared { usb_dev, serial }, Local {}, init::Monotonics())
}
Expand Down
Loading