stm32-rs / stm32f0xx-hal

A Rust `embedded-hal` implementation for all MCUs in the STM32 F0 family
BSD Zero Clause License
134 stars 59 forks source link

Have PA9/10/11/12 USB pins automatically remap? #118

Closed brainstorm closed 4 years ago

brainstorm commented 4 years ago

I was going a bit nuts because my board was not USB-enumerating (for a seemingly simple RTIC example) and it turned out to be that I didn't uncomment those:

        /* 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());

Fortunately, @mvirkkunen and other very helpful folks at rust-embedded discord channel pointed that out...

Now, would it be at all possible to detect those different variants automatically, somehow?

mvirkkunen commented 4 years ago

I think it might be possible by creating a different Peripheral struct for the PA9/PA10 pins that's available on certain devices, and having the enable function remap them. Or alternatively have a special constructor for it.

Edit: ...to do the remapping without having to mess with the registers by hand, that is. It's probably not possible to detect which chips have which pins, because it's package dependent.

therealprof commented 4 years ago

I don't see how. The chips are just bonded into different packages and are not self-aware of how they're bonded.

brainstorm commented 4 years ago

...to do the remapping without having to mess with the registers by hand, that is. It's probably not possible to detect which chips have which pins, because it's package dependent.

Yes, I meant this, sorry for the confusion @therealprof, I should have phrased that better :-S

therealprof commented 4 years ago

@brainstorm Thanks for the clarification. Yes, that makes absolute sense.

Want to take a stab at it?

brainstorm commented 4 years ago

Sure, I have no idea on what I'm doing, but let's take it on PR #119 ;)