diff --git a/embassy-stm32/build.rs b/embassy-stm32/build.rs index a0b74c0b9..64d8afa13 100644 --- a/embassy-stm32/build.rs +++ b/embassy-stm32/build.rs @@ -601,7 +601,7 @@ fn main() { .iter() .map(|(_fieldset, fieldname, enum_name)| { quote! { - pub #fieldname: Option + pub #fieldname: Option<#enum_name> } }) .collect(); @@ -627,23 +627,32 @@ fn main() { }) .collect(); - g.extend(quote! { - #[derive(Clone, Copy)] - pub struct ClockMux { - #( #struct_fields, )* - } + let enum_names: BTreeSet<_> = rcc_cfgr_regs + .iter() + .map(|(_fieldset, _fieldname, enum_name)| enum_name) + .collect(); - impl Default for ClockMux { - fn default() -> Self { - Self { - #( #field_names: None, )* + g.extend(quote! { + pub mod mux { + #(pub use crate::pac::rcc::vals::#enum_names as #enum_names; )* + + #[derive(Clone, Copy)] + pub struct ClockMux { + #( #struct_fields, )* + } + + impl Default for ClockMux { + fn default() -> Self { + Self { + #( #field_names: None, )* + } } } - } - impl ClockMux { - pub fn init(self) { - #( #inits )* + impl ClockMux { + pub fn init(self) { + #( #inits )* + } } } }); diff --git a/embassy-stm32/src/rcc/f013.rs b/embassy-stm32/src/rcc/f013.rs index 86af4bd68..de209272d 100644 --- a/embassy-stm32/src/rcc/f013.rs +++ b/embassy-stm32/src/rcc/f013.rs @@ -97,10 +97,9 @@ pub struct Config { pub adc: AdcClockSource, #[cfg(all(stm32f3, not(rcc_f37), adc3_common))] pub adc34: AdcClockSource, - #[cfg(stm32f334)] - pub hrtim: HrtimClockSource, + #[cfg(clock_mux)] - pub mux: crate::rcc::ClockMux, + pub mux: crate::rcc::mux::ClockMux, pub ls: super::LsConfig, } @@ -128,8 +127,7 @@ impl Default for Config { adc: AdcClockSource::Hclk(AdcHclkPrescaler::Div1), #[cfg(all(stm32f3, not(rcc_f37), adc3_common))] adc34: AdcClockSource::Hclk(AdcHclkPrescaler::Div1), - #[cfg(stm32f334)] - hrtim: HrtimClockSource::BusClk, + #[cfg(clock_mux)] mux: Default::default(), } @@ -350,7 +348,8 @@ pub(crate) unsafe fn init(config: Config) { } }; - #[cfg(stm32f334)] + /* + TODO: Maybe add something like this to clock_mux? How can we autogenerate the data for this? let hrtim = match config.hrtim { // Must be configured after the bus is ready, otherwise it won't work HrtimClockSource::BusClk => None, @@ -366,6 +365,7 @@ pub(crate) unsafe fn init(config: Config) { Some(pll * 2u32) } }; + */ #[cfg(clock_mux)] config.mux.init(); @@ -384,8 +384,6 @@ pub(crate) unsafe fn init(config: Config) { adc: Some(adc), #[cfg(all(stm32f3, not(rcc_f37), adc3_common))] adc34: Some(adc34), - #[cfg(stm32f334)] - hrtim: hrtim, rtc: rtc, hsi48: hsi48, #[cfg(any(rcc_f1, rcc_f1cl, stm32f3))] diff --git a/embassy-stm32/src/rcc/mod.rs b/embassy-stm32/src/rcc/mod.rs index 24516d426..b5a8bc2a4 100644 --- a/embassy-stm32/src/rcc/mod.rs +++ b/embassy-stm32/src/rcc/mod.rs @@ -32,7 +32,7 @@ mod _version; pub use _version::*; #[cfg(clock_mux)] -pub use crate::_generated::ClockMux; +pub use crate::_generated::mux as mux; pub use crate::_generated::Clocks; #[cfg(feature = "low-power")] diff --git a/examples/stm32f334/src/bin/pwm.rs b/examples/stm32f334/src/bin/pwm.rs index cf5eb7b26..7c6d6cd71 100644 --- a/examples/stm32f334/src/bin/pwm.rs +++ b/examples/stm32f334/src/bin/pwm.rs @@ -28,9 +28,7 @@ async fn main(_spawner: Spawner) { config.rcc.apb1_pre = APBPrescaler::DIV2; config.rcc.apb2_pre = APBPrescaler::DIV1; - // TODO: The two lines here do the same thing - config.rcc.hrtim = HrtimClockSource::PllClk; - config.rcc.mux.hrtim1sw = Some(embassy_stm32::pac::rcc::vals::Timsw::PLL1_P); + config.rcc.mux.hrtim1sw = Some(embassy_stm32::rcc::mux::Timsw::PLL1_P); } let p = embassy_stm32::init(config);