diff options
| author | Gerzain Mata <[email protected]> | 2025-07-24 16:28:59 -0700 |
|---|---|---|
| committer | Gerzain Mata <[email protected]> | 2025-07-24 16:28:59 -0700 |
| commit | a8d215ff1484cde754695b08e91663e2220c9790 (patch) | |
| tree | 5dcb775578a0da34137a7e2fc821c9dd4a0d0a34 /examples | |
| parent | c5565ccc288863b7d7e5a82aa42141eb7a1cff9f (diff) | |
Partially working USB example
Diffstat (limited to 'examples')
| -rw-r--r-- | examples/stm32wba/src/bin/usb_hs_serial.rs | 20 |
1 files changed, 10 insertions, 10 deletions
diff --git a/examples/stm32wba/src/bin/usb_hs_serial.rs b/examples/stm32wba/src/bin/usb_hs_serial.rs index e30f33625..bda4a5013 100644 --- a/examples/stm32wba/src/bin/usb_hs_serial.rs +++ b/examples/stm32wba/src/bin/usb_hs_serial.rs | |||
| @@ -5,7 +5,7 @@ use defmt::{panic, *}; | |||
| 5 | use defmt_rtt as _; // global logger | 5 | use defmt_rtt as _; // global logger |
| 6 | use embassy_executor::Spawner; | 6 | use embassy_executor::Spawner; |
| 7 | use embassy_futures::join::join; | 7 | use embassy_futures::join::join; |
| 8 | use embassy_stm32::rcc::PllSource; | 8 | use embassy_stm32::rcc::{PllSource, PllPreDiv, PllMul, PllDiv}; |
| 9 | use embassy_stm32::rcc::{mux, AHBPrescaler, APBPrescaler, Hse, HsePrescaler, Sysclk, VoltageScale}; | 9 | use embassy_stm32::rcc::{mux, AHBPrescaler, APBPrescaler, Hse, HsePrescaler, Sysclk, VoltageScale}; |
| 10 | use embassy_stm32::usb::{Driver, Instance}; | 10 | use embassy_stm32::usb::{Driver, Instance}; |
| 11 | use embassy_stm32::{bind_interrupts, peripherals, usb, Config}; | 11 | use embassy_stm32::{bind_interrupts, peripherals, usb, Config}; |
| @@ -26,21 +26,18 @@ async fn main(_spawner: Spawner) { | |||
| 26 | 26 | ||
| 27 | // External HSE (32 MHz) setup | 27 | // External HSE (32 MHz) setup |
| 28 | config.rcc.hse = Some(Hse { | 28 | config.rcc.hse = Some(Hse { |
| 29 | prescaler: HsePrescaler::DIV1, | 29 | prescaler: HsePrescaler::DIV2, |
| 30 | }); | 30 | }); |
| 31 | 31 | ||
| 32 | // route HSE into the USB‐OTG‐HS block | ||
| 33 | config.rcc.mux.otghssel = mux::Otghssel::HSE; | ||
| 34 | config.rcc.sys = Sysclk::HSE; | ||
| 35 | 32 | ||
| 36 | // Fine-tune PLL1 dividers/multipliers | 33 | // Fine-tune PLL1 dividers/multipliers |
| 37 | config.rcc.pll1 = Some(embassy_stm32::rcc::Pll { | 34 | config.rcc.pll1 = Some(embassy_stm32::rcc::Pll { |
| 38 | source: PllSource::HSE, | 35 | source: PllSource::HSE, |
| 39 | pllm: 2.into(), // PLLM = 2 → HSE / 2 = 16 MHz input | 36 | prediv: PllPreDiv::DIV2, // PLLM = 2 → HSE / 2 = 8 MHz |
| 40 | mul: 12.into(), // PLLN = 12 → 16 MHz * 12 = 192 MHz VCO | 37 | mul: PllMul::MUL60, // PLLN = 60 → 8 MHz * 60 = 480 MHz VCO |
| 41 | divp: Some(2.into()), // PLLP = 2 → 96 MHz | 38 | divr: Some(PllDiv::DIV5), // PLLR = 5 → 96 MHz (Sysclk) |
| 42 | divq: Some(2.into()), // PLLQ = 2 → 96 MHz | 39 | divq: Some(PllDiv::DIV10), // PLLQ = 10 → 48 MHz (USB) |
| 43 | divr: Some(2.into()), // PLLR = 2 → 96 MHz | 40 | divp: Some(PllDiv::DIV15), // PLLP = 15 → 32 MHz (USBOTG) |
| 44 | frac: Some(4096), // Fractional part (enabled) | 41 | frac: Some(4096), // Fractional part (enabled) |
| 45 | }); | 42 | }); |
| 46 | 43 | ||
| @@ -51,6 +48,9 @@ async fn main(_spawner: Spawner) { | |||
| 51 | 48 | ||
| 52 | // voltage scale for max performance | 49 | // voltage scale for max performance |
| 53 | config.rcc.voltage_scale = VoltageScale::RANGE1; | 50 | config.rcc.voltage_scale = VoltageScale::RANGE1; |
| 51 | // route PLL1_P into the USB‐OTG‐HS block | ||
| 52 | config.rcc.mux.otghssel = mux::Otghssel::PLL1_P; | ||
| 53 | config.rcc.sys = Sysclk::PLL1_R; | ||
| 54 | 54 | ||
| 55 | let p = embassy_stm32::init(config); | 55 | let p = embassy_stm32::init(config); |
| 56 | 56 | ||
