diff options
| author | Barnaby Walters <[email protected]> | 2024-02-16 20:32:35 +0100 |
|---|---|---|
| committer | Barnaby Walters <[email protected]> | 2024-02-16 20:32:35 +0100 |
| commit | ae748339999034854a78629c2e2f160d0d8417f9 (patch) | |
| tree | 4c0783c534c0d0794ff813983466d3374e868bb1 | |
| parent | 32e4c93954abb3add1c9b2c8fff627c497d47258 (diff) | |
Removed redundant HSI48 configuration
| -rw-r--r-- | embassy-stm32/src/rcc/g4.rs | 32 | ||||
| -rw-r--r-- | examples/stm32g4/src/bin/usb_serial.rs | 7 |
2 files changed, 14 insertions, 25 deletions
diff --git a/embassy-stm32/src/rcc/g4.rs b/embassy-stm32/src/rcc/g4.rs index 5ac933af4..7ca741fc7 100644 --- a/embassy-stm32/src/rcc/g4.rs +++ b/embassy-stm32/src/rcc/g4.rs | |||
| @@ -3,8 +3,9 @@ use stm32_metapac::rcc::vals::{Adcsel, Sw}; | |||
| 3 | use stm32_metapac::FLASH; | 3 | use stm32_metapac::FLASH; |
| 4 | 4 | ||
| 5 | pub use crate::pac::rcc::vals::{ | 5 | pub use crate::pac::rcc::vals::{ |
| 6 | Adcsel as AdcClockSource, Clk48sel, Fdcansel as FdCanClockSource, Hpre as AHBPrescaler, Pllm as PllPreDiv, | 6 | Adcsel as AdcClockSource, Clk48sel as Clk48Src, Fdcansel as FdCanClockSource, Hpre as AHBPrescaler, |
| 7 | Plln as PllMul, Pllp as PllPDiv, Pllq as PllQDiv, Pllr as PllRDiv, Pllsrc, Ppre as APBPrescaler, Sw as Sysclk, | 7 | Pllm as PllPreDiv, Plln as PllMul, Pllp as PllPDiv, Pllq as PllQDiv, Pllr as PllRDiv, Pllsrc, Ppre as APBPrescaler, |
| 8 | Sw as Sysclk, | ||
| 8 | }; | 9 | }; |
| 9 | use crate::pac::{PWR, RCC}; | 10 | use crate::pac::{PWR, RCC}; |
| 10 | use crate::time::Hertz; | 11 | use crate::time::Hertz; |
| @@ -53,17 +54,6 @@ pub struct Pll { | |||
| 53 | pub divr: Option<PllRDiv>, | 54 | pub divr: Option<PllRDiv>, |
| 54 | } | 55 | } |
| 55 | 56 | ||
| 56 | /// Sets the source for the 48MHz clock to the USB and RNG peripherals. | ||
| 57 | pub enum Clock48MhzSrc { | ||
| 58 | /// Use the High Speed Internal Oscillator. For USB usage, the CRS must be used to calibrate the | ||
| 59 | /// oscillator to comply with the USB specification for oscillator tolerance. | ||
| 60 | Hsi48(super::Hsi48Config), | ||
| 61 | /// Use the PLLQ output. The PLL must be configured to output a 48MHz clock. For USB usage the | ||
| 62 | /// PLL needs to be using the HSE source to comply with the USB specification for oscillator | ||
| 63 | /// tolerance. | ||
| 64 | PllQ, | ||
| 65 | } | ||
| 66 | |||
| 67 | /// Clocks configutation | 57 | /// Clocks configutation |
| 68 | #[non_exhaustive] | 58 | #[non_exhaustive] |
| 69 | pub struct Config { | 59 | pub struct Config { |
| @@ -82,7 +72,7 @@ pub struct Config { | |||
| 82 | pub low_power_run: bool, | 72 | pub low_power_run: bool, |
| 83 | 73 | ||
| 84 | /// Sets the clock source for the 48MHz clock used by the USB and RNG peripherals. | 74 | /// Sets the clock source for the 48MHz clock used by the USB and RNG peripherals. |
| 85 | pub clk48_src: Option<Clock48MhzSrc>, | 75 | pub clk48_src: Clk48Src, |
| 86 | 76 | ||
| 87 | pub ls: super::LsConfig, | 77 | pub ls: super::LsConfig, |
| 88 | 78 | ||
| @@ -106,7 +96,7 @@ impl Default for Config { | |||
| 106 | apb1_pre: APBPrescaler::DIV1, | 96 | apb1_pre: APBPrescaler::DIV1, |
| 107 | apb2_pre: APBPrescaler::DIV1, | 97 | apb2_pre: APBPrescaler::DIV1, |
| 108 | low_power_run: false, | 98 | low_power_run: false, |
| 109 | clk48_src: Some(Clock48MhzSrc::Hsi48(Default::default())), | 99 | clk48_src: Clk48Src::HSI48, |
| 110 | ls: Default::default(), | 100 | ls: Default::default(), |
| 111 | adc12_clock_source: Adcsel::DISABLE, | 101 | adc12_clock_source: Adcsel::DISABLE, |
| 112 | adc345_clock_source: Adcsel::DISABLE, | 102 | adc345_clock_source: Adcsel::DISABLE, |
| @@ -283,19 +273,17 @@ pub(crate) unsafe fn init(config: Config) { | |||
| 283 | }; | 273 | }; |
| 284 | 274 | ||
| 285 | // Setup the 48 MHz clock if needed | 275 | // Setup the 48 MHz clock if needed |
| 286 | if let Some(clock_48mhz_src) = config.clk48_src { | 276 | { |
| 287 | let source = match clock_48mhz_src { | 277 | let source = match config.clk48_src { |
| 288 | Clock48MhzSrc::PllQ => { | 278 | Clk48Src::PLL1_Q => { |
| 289 | // Make sure the PLLQ is enabled and running at 48Mhz | 279 | // Make sure the PLLQ is enabled and running at 48Mhz |
| 290 | let pllq_freq = pll_freq.as_ref().and_then(|f| f.pll_q); | 280 | let pllq_freq = pll_freq.as_ref().and_then(|f| f.pll_q); |
| 291 | assert!(pllq_freq.is_some() && pllq_freq.unwrap().0 == 48_000_000); | 281 | assert!(pllq_freq.is_some() && pllq_freq.unwrap().0 == 48_000_000); |
| 292 | 282 | ||
| 293 | crate::pac::rcc::vals::Clk48sel::PLL1_Q | 283 | crate::pac::rcc::vals::Clk48sel::PLL1_Q |
| 294 | } | 284 | } |
| 295 | Clock48MhzSrc::Hsi48(config) => { | 285 | Clk48Src::HSI48 => crate::pac::rcc::vals::Clk48sel::HSI48, |
| 296 | super::init_hsi48(config); | 286 | _ => unreachable!(), |
| 297 | crate::pac::rcc::vals::Clk48sel::HSI48 | ||
| 298 | } | ||
| 299 | }; | 287 | }; |
| 300 | 288 | ||
| 301 | RCC.ccipr().modify(|w| w.set_clk48sel(source)); | 289 | RCC.ccipr().modify(|w| w.set_clk48sel(source)); |
diff --git a/examples/stm32g4/src/bin/usb_serial.rs b/examples/stm32g4/src/bin/usb_serial.rs index d9207e4cd..353ac1799 100644 --- a/examples/stm32g4/src/bin/usb_serial.rs +++ b/examples/stm32g4/src/bin/usb_serial.rs | |||
| @@ -4,7 +4,7 @@ | |||
| 4 | use defmt::{panic, *}; | 4 | use defmt::{panic, *}; |
| 5 | use embassy_executor::Spawner; | 5 | use embassy_executor::Spawner; |
| 6 | use embassy_stm32::rcc::{ | 6 | use embassy_stm32::rcc::{ |
| 7 | Clock48MhzSrc, Hse, HseMode, Hsi48Config, Pll, PllMul, PllPreDiv, PllQDiv, PllRDiv, Pllsrc, Sysclk, | 7 | Clk48Src, Hse, HseMode, Hsi48Config, Pll, PllMul, PllPreDiv, PllQDiv, PllRDiv, Pllsrc, Sysclk, |
| 8 | }; | 8 | }; |
| 9 | use embassy_stm32::time::Hertz; | 9 | use embassy_stm32::time::Hertz; |
| 10 | use embassy_stm32::usb::{self, Driver, Instance}; | 10 | use embassy_stm32::usb::{self, Driver, Instance}; |
| @@ -47,9 +47,10 @@ async fn main(_spawner: Spawner) { | |||
| 47 | 47 | ||
| 48 | if USE_HSI48 { | 48 | if USE_HSI48 { |
| 49 | // Sets up the Clock Recovery System (CRS) to use the USB SOF to trim the HSI48 oscillator. | 49 | // Sets up the Clock Recovery System (CRS) to use the USB SOF to trim the HSI48 oscillator. |
| 50 | config.rcc.clk48_src = Some(Clock48MhzSrc::Hsi48(Hsi48Config { sync_from_usb: true })); | 50 | config.rcc.hsi48 = Some(Hsi48Config { sync_from_usb: true }); |
| 51 | config.rcc.clk48_src = Clk48Src::HSI48; | ||
| 51 | } else { | 52 | } else { |
| 52 | config.rcc.clk48_src = Some(Clock48MhzSrc::PllQ); | 53 | config.rcc.clk48_src = Clk48Src::PLL1_Q; |
| 53 | } | 54 | } |
| 54 | 55 | ||
| 55 | let p = embassy_stm32::init(config); | 56 | let p = embassy_stm32::init(config); |
