diff options
| author | Gerzain Mata <[email protected]> | 2025-07-23 04:54:42 -0700 |
|---|---|---|
| committer | Gerzain Mata <[email protected]> | 2025-07-23 04:54:42 -0700 |
| commit | 378035aa9171b3ff6ab3b6b49f5970151a99115f (patch) | |
| tree | d79fdf50e5c09693186c8f323175bd3bbcf59e74 /examples | |
| parent | e2cec28805a66fa913fcdc3af2de07b95b06aa0d (diff) | |
Added PLL HAL code for STM32WBA
Diffstat (limited to 'examples')
| -rw-r--r-- | examples/stm32wba/src/bin/usb_hs_serial.rs | 26 |
1 files changed, 23 insertions, 3 deletions
diff --git a/examples/stm32wba/src/bin/usb_hs_serial.rs b/examples/stm32wba/src/bin/usb_hs_serial.rs index 1ffd94906..be2d0a4e5 100644 --- a/examples/stm32wba/src/bin/usb_hs_serial.rs +++ b/examples/stm32wba/src/bin/usb_hs_serial.rs | |||
| @@ -7,9 +7,10 @@ use embassy_executor::Spawner; | |||
| 7 | use embassy_futures::join::join; | 7 | use embassy_futures::join::join; |
| 8 | use embassy_stm32::usb::{Driver, Instance}; | 8 | use embassy_stm32::usb::{Driver, Instance}; |
| 9 | use embassy_stm32::{bind_interrupts, peripherals, usb, Config}; | 9 | use embassy_stm32::{bind_interrupts, peripherals, usb, Config}; |
| 10 | use embassy_stm32::rcc::{VoltageScale, Hse, HsePrescaler, Sysclk, mux}; | 10 | use embassy_stm32::rcc::{VoltageScale, Hse, HsePrescaler, APBPrescaler, AHBPrescaler, Sysclk, mux}; |
| 11 | use embassy_usb::class::cdc_acm::{CdcAcmClass, State}; | 11 | use embassy_usb::class::cdc_acm::{CdcAcmClass, State}; |
| 12 | use embassy_usb::driver::EndpointError; | 12 | use embassy_usb::driver::EndpointError; |
| 13 | use embassy_stm32::rcc::PllSource; | ||
| 13 | use embassy_usb::Builder; | 14 | use embassy_usb::Builder; |
| 14 | use panic_probe as _; | 15 | use panic_probe as _; |
| 15 | 16 | ||
| @@ -23,12 +24,31 @@ async fn main(_spawner: Spawner) { | |||
| 23 | 24 | ||
| 24 | let mut config = Config::default(); | 25 | let mut config = Config::default(); |
| 25 | 26 | ||
| 26 | // ── Run off the external 32 MHz crystal directly ── | 27 | // External HSE (32 MHz) setup |
| 27 | config.rcc.hse = Some(Hse { prescaler: HsePrescaler::DIV1 }); | 28 | config.rcc.hse = Some(Hse { prescaler: HsePrescaler::DIV1 }); |
| 28 | config.rcc.sys = Sysclk::HSE; | 29 | |
| 29 | // route HSE into the USB‐OTG‐HS block | 30 | // route HSE into the USB‐OTG‐HS block |
| 30 | config.rcc.mux.otghssel = mux::Otghssel::HSE; | 31 | config.rcc.mux.otghssel = mux::Otghssel::HSE; |
| 31 | config.rcc.sys = Sysclk::HSE; | 32 | config.rcc.sys = Sysclk::HSE; |
| 33 | |||
| 34 | // Fine-tune PLL1 dividers/multipliers | ||
| 35 | config.rcc.pll1 = Some(embassy_stm32::rcc::Pll { | ||
| 36 | source: PllSource::HSE, | ||
| 37 | pllm: 2, // PLLM = 2 → HSE / 2 = 16 MHz input | ||
| 38 | mul: 12, // PLLN = 12 → 16 MHz * 12 = 192 MHz VCO | ||
| 39 | divp: Some(2), // PLLP = 2 → 96 MHz | ||
| 40 | divq: Some(2), // PLLQ = 2 → 96 MHz | ||
| 41 | divr: Some(2), // PLLR = 2 → 96 MHz | ||
| 42 | frac: Some(4096), // Fractional part (enabled) | ||
| 43 | }); | ||
| 44 | |||
| 45 | |||
| 46 | config.rcc.ahb_pre = AHBPrescaler::DIV1; | ||
| 47 | config.rcc.apb1_pre = APBPrescaler::DIV1; | ||
| 48 | config.rcc.apb2_pre = APBPrescaler::DIV1; | ||
| 49 | config.rcc.apb7_pre = APBPrescaler::DIV1; | ||
| 50 | |||
| 51 | // voltage scale for max performance | ||
| 32 | config.rcc.voltage_scale = VoltageScale::RANGE1; | 52 | config.rcc.voltage_scale = VoltageScale::RANGE1; |
| 33 | 53 | ||
| 34 | let p = embassy_stm32::init(config); | 54 | let p = embassy_stm32::init(config); |
