-
Notifications
You must be signed in to change notification settings - Fork 48
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
USB device support and usb_serial example #50
base: master
Are you sure you want to change the base?
Conversation
6a8fabe
to
1b44464
Compare
This was tested on an STM32G473 on a custom board with an external 8MHz oscillator
1b44464
to
91f65b8
Compare
//! This example currently requires an 8MHz external oscillator | ||
//! and assumed an LED is connected to port A6. | ||
//! | ||
//! Further work could be done to setup the HSI48 and the clock |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This comment is done now
// - APB1 = PCLK1 = 72 MHz | ||
// - APB2 = PCLK2 = 72 MHz | ||
// - USB = 48 MHz | ||
let mut rcc = rcc.freeze( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since we have the CRS support now this could be reworked to not depend on the HSE at all. Would make it easier to run on other hardware.
configure_usb_clock_source(ClockSource::Hsi48, &rcc); | ||
|
||
// Configure an LED | ||
let gpioa = dp.GPIOA.split(&mut rcc); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The LED is probably a distraction. Take it out to simplify stuff.
.build(); | ||
|
||
loop { | ||
if !usb_dev.poll(&mut [&mut serial]) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A separate example or rework this one to poll in an interrupt would be good. Calling poll from the main loop is not super useful for anything but the most trivial of projects.
@@ -85,3 +85,6 @@ pub mod syscfg; | |||
pub mod time; | |||
pub mod timer; | |||
// pub mod watchdog; | |||
|
|||
#[cfg(all(feature = "stm32-usbd", any(feature = "stm32g473",)))] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The machine feature needs changed here. Do all G4's have USB?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Per ST's website, yes they all have USB. I've been bringing a G431 up and this is the only line that needed adjusting. G431 is the minimum spec G4 available.
/// Sets up the clock recovery system for the HSI48 oscillator. | ||
/// TODO: make this configurable for more than just USB applications. | ||
pub fn configure(self, crs_config: CrsConfig, rcc: &Rcc) -> Self { | ||
// TODO: This needs to ensure that the HSI48 is enabled |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some of this is done
} | ||
|
||
#[inline(always)] | ||
pub fn configure_usb_clock_source(cs: ClockSource, rcc: &Rcc) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the HSI48 is selected, can this do the configuration of it?
q: Some(PllQDiv::DIV_6), | ||
p: None, | ||
}) | ||
.ahb_psc(Prescaler::Div2) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thought it was worth mentioning because I noticed in test, this div2 is setting the HCLK to 72Mhz -- differs from the comment above.
I'm bringing up a g431 with usbd-serial and everything is working great so far. Works with CRS and with HSE+PLL configured for the 12Mhz crystal on a custom board. |
Draft PR to go in after the separate #49 to ease review.
This PR adds the following features:
This has been tested on a custom STM32F473 board. If desired I can split this out into separate PRs for the defmt/probe-run and the USB support.