Skip to content

Commit fa3f2c2

Browse files
Merge #129
129: Update `remap_pins` stuff r=therealprof a=david-sawatzke I'd also prefer it taking the hal `Rcc`, but that'd be a breaking change. @therealprof Your thoughts? Co-authored-by: David Sawatzke <[email protected]>
2 parents a7daf77 + 8e3b982 commit fa3f2c2

File tree

2 files changed

+13
-15
lines changed

2 files changed

+13
-15
lines changed

examples/usb_serial.rs

+9-9
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,15 @@ use usbd_serial::{SerialPort, USB_CLASS_CDC};
1515
fn main() -> ! {
1616
let mut dp = pac::Peripherals::take().unwrap();
1717

18+
/*
19+
* IMPORTANT: if you have a chip in TSSOP20 (STM32F042F) or UFQFPN28 (STM32F042G) package,
20+
* and want to use USB, make sure you call `remap_pins(rcc, syscfg)`, otherwise the device will not enumerate.
21+
*
22+
* Uncomment the following function if the situation above applies to you.
23+
*/
24+
25+
// stm32f0xx_hal::usb::remap_pins(&mut dp.RCC, &mut dp.SYSCFG);
26+
1827
let mut rcc = dp
1928
.RCC
2029
.configure()
@@ -41,15 +50,6 @@ fn main() -> ! {
4150

4251
let mut serial = SerialPort::new(&usb_bus);
4352

44-
/*
45-
* IMPORTANT: if you have a chip in TSSOP20 (STM32F042F) or UFQFPN28 (STM32F042G) package,
46-
* and want to use USB, make sure you call `remap_pins(rcc, syscfg)`, otherwise the device will not enumerate.
47-
*
48-
* Uncomment the following function if the situation above applies to you.
49-
*/
50-
51-
//usb_bus.remap_pins();
52-
5353
let mut usb_dev = UsbDeviceBuilder::new(&usb_bus, UsbVidPid(0x16c0, 0x27dd))
5454
.manufacturer("Fake company")
5555
.product("Serial port")

src/usb.rs

+4-6
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,11 @@ unsafe impl UsbPeripheral for Peripheral {
4646
}
4747
}
4848

49+
/// Remap PA11/PA12 pins to PA09/PA10 for USB on
50+
/// TSSOP20 (STM32F042F) or UFQFPN28 (STM32F042G) packages
4951
pub fn remap_pins(rcc: &mut RCC, syscfg: &mut SYSCFG) {
50-
cortex_m::interrupt::free(|_| {
51-
// Remap PA11/PA12 pins to PA09/PA10 for USB on
52-
// TSSOP20 (STM32F042F) or UFQFPN28 (STM32F042G) packages
53-
rcc.apb2enr.modify(|_, w| w.syscfgen().set_bit());
54-
syscfg.cfgr1.modify(|_, w| w.pa11_pa12_rmp().remapped());
55-
});
52+
rcc.apb2enr.modify(|_, w| w.syscfgen().set_bit());
53+
syscfg.cfgr1.modify(|_, w| w.pa11_pa12_rmp().remapped());
5654
}
5755

5856
pub type UsbBusType = UsbBus<Peripheral>;

0 commit comments

Comments
 (0)