Merge pull request from Ecco/stm32wba-fixed-hse

STM32WBA's high speed external clock has to run at 32 MHz
This commit is contained in:
Dario Nieuwenhuis 2024-02-01 19:03:35 +00:00 committed by GitHub
commit c4839e4671
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -6,26 +6,28 @@ use crate::time::Hertz;
/// HSI speed /// HSI speed
pub const HSI_FREQ: Hertz = Hertz(16_000_000); pub const HSI_FREQ: Hertz = Hertz(16_000_000);
// HSE speed
pub const HSE_FREQ: Hertz = Hertz(32_000_000);
pub use crate::pac::pwr::vals::Vos as VoltageScale; pub use crate::pac::pwr::vals::Vos as VoltageScale;
pub use crate::pac::rcc::vals::{Hpre as AHBPrescaler, Ppre as APBPrescaler}; pub use crate::pac::rcc::vals::{Hpre as AHBPrescaler, Ppre as APBPrescaler};
#[derive(Copy, Clone)] #[derive(Copy, Clone)]
pub enum ClockSrc { pub enum ClockSrc {
HSE(Hertz), HSE,
HSI, HSI,
} }
#[derive(Clone, Copy, Debug)] #[derive(Clone, Copy, Debug)]
pub enum PllSource { pub enum PllSource {
HSE(Hertz), HSE,
HSI, HSI,
} }
impl Into<Pllsrc> for PllSource { impl Into<Pllsrc> for PllSource {
fn into(self) -> Pllsrc { fn into(self) -> Pllsrc {
match self { match self {
PllSource::HSE(..) => Pllsrc::HSE, PllSource::HSE => Pllsrc::HSE,
PllSource::HSI => Pllsrc::HSI, PllSource::HSI => Pllsrc::HSI,
} }
} }
@ -34,7 +36,7 @@ impl Into<Pllsrc> for PllSource {
impl Into<Sw> for ClockSrc { impl Into<Sw> for ClockSrc {
fn into(self) -> Sw { fn into(self) -> Sw {
match self { match self {
ClockSrc::HSE(..) => Sw::HSE, ClockSrc::HSE => Sw::HSE,
ClockSrc::HSI => Sw::HSI, ClockSrc::HSI => Sw::HSI,
} }
} }
@ -64,11 +66,11 @@ impl Default for Config {
pub(crate) unsafe fn init(config: Config) { pub(crate) unsafe fn init(config: Config) {
let sys_clk = match config.mux { let sys_clk = match config.mux {
ClockSrc::HSE(freq) => { ClockSrc::HSE => {
RCC.cr().write(|w| w.set_hseon(true)); RCC.cr().write(|w| w.set_hseon(true));
while !RCC.cr().read().hserdy() {} while !RCC.cr().read().hserdy() {}
freq HSE_FREQ
} }
ClockSrc::HSI => { ClockSrc::HSI => {
RCC.cr().write(|w| w.set_hsion(true)); RCC.cr().write(|w| w.set_hsion(true));