Browse Source

Move usb-remap internals for certain ICs to USB enable() (#119)

Move usb-remap internals for certain ICs to USB enable()
staging
Roman Valls Guimera 1 year ago
committed by GitHub
parent
commit
0bbb50f5fa
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      CHANGELOG.md
  2. 17
      examples/usb_serial.rs
  3. 13
      src/usb.rs

2
CHANGELOG.md

@ -7,6 +7,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
## [Unreleased]
- Simplify USB PA11/12 remapping for STM32F042x via `usb_bus.usb_remap()` function.
## [v0.17.0] - 2020-06-27
### Changed

17
examples/usb_serial.rs

@ -15,13 +15,6 @@ use usbd_serial::{SerialPort, USB_CLASS_CDC};
fn main() -> ! {
let mut dp = pac::Peripherals::take().unwrap();
/* Uncomment the following lines if you have a chip in TSSOP20 (STM32F042F)
or UFQFPN28 (STM32F042G) package
This code enables clock for SYSCFG and remaps USB pins to PA9 and PA10.
*/
//dp.RCC.apb2enr.modify(|_, w| w.syscfgen().set_bit());
//dp.SYSCFG.cfgr1.modify(|_, w| w.pa11_pa12_rmp().remapped());
let mut rcc = dp
.RCC
.configure()
@ -43,10 +36,20 @@ fn main() -> ! {
pin_dm: gpioa.pa11,
pin_dp: gpioa.pa12,
};
let usb_bus = UsbBus::new(usb);
let mut serial = SerialPort::new(&usb_bus);
/*
* IMPORTANT: if you have a chip in TSSOP20 (STM32F042F) or UFQFPN28 (STM32F042G) package,
* and want to use USB, make sure you call `remap_pins(rcc, syscfg)`, otherwise the device will not enumerate.
*
* Uncomment the following function if the situation above applies to you.
*/
//usb_bus.remap_pins();
let mut usb_dev = UsbDeviceBuilder::new(&usb_bus, UsbVidPid(0x16c0, 0x27dd))
.manufacturer("Fake company")
.product("Serial port")

13
src/usb.rs

@ -5,7 +5,7 @@
//! See <https://github.com/stm32-rs/stm32f0xx-hal/tree/master/examples>
//! for usage examples.
use crate::pac::{RCC, USB};
use crate::pac::{RCC, SYSCFG, USB};
use stm32_usbd::UsbPeripheral;
use crate::gpio::gpioa::{PA11, PA12};
@ -27,7 +27,7 @@ unsafe impl UsbPeripheral for Peripheral {
const EP_MEMORY_SIZE: usize = 1024;
fn enable() {
let rcc = unsafe { (&*RCC::ptr()) };
let rcc = unsafe { &*RCC::ptr() };
cortex_m::interrupt::free(|_| {
// Enable USB peripheral
@ -46,4 +46,13 @@ unsafe impl UsbPeripheral for Peripheral {
}
}
pub fn remap_pins(rcc: &mut RCC, syscfg: &mut SYSCFG) {
cortex_m::interrupt::free(|_| {
// Remap PA11/PA12 pins to PA09/PA10 for USB on
// TSSOP20 (STM32F042F) or UFQFPN28 (STM32F042G) packages
rcc.apb2enr.modify(|_, w| w.syscfgen().set_bit());
syscfg.cfgr1.modify(|_, w| w.pa11_pa12_rmp().remapped());
});
}
pub type UsbBusType = UsbBus<Peripheral>;

Loading…
Cancel
Save