From cdc66e110f084a27b2bae61d0611c884fcc5f845 Mon Sep 17 00:00:00 2001 From: Dario Nieuwenhuis Date: Tue, 4 Jan 2022 11:18:59 +0100 Subject: [PATCH 1/3] stm32/rcc: remove builders on Config. This makes API consistent with other Config structs in Embassy, where the convention is to not use builders. --- embassy-stm32/src/rcc/g0/mod.rs | 34 +++------------------- embassy-stm32/src/rcc/g4/mod.rs | 42 ++++----------------------- embassy-stm32/src/rcc/l0/mod.rs | 34 +++------------------- embassy-stm32/src/rcc/l1/mod.rs | 34 +++------------------- embassy-stm32/src/rcc/l4/mod.rs | 34 +++------------------- embassy-stm32/src/rcc/u5/mod.rs | 22 +++++--------- embassy-stm32/src/rcc/wb/mod.rs | 34 +++------------------- embassy-stm32/src/rcc/wl5x/mod.rs | 34 +++------------------- examples/stm32l0/src/bin/lorawan.rs | 2 +- examples/stm32l4/src/bin/rng.rs | 4 +-- examples/stm32wl55/src/bin/lorawan.rs | 2 +- examples/stm32wl55/src/bin/subghz.rs | 2 +- 12 files changed, 42 insertions(+), 236 deletions(-) diff --git a/embassy-stm32/src/rcc/g0/mod.rs b/embassy-stm32/src/rcc/g0/mod.rs index 103d9a84..7f7af2fc 100644 --- a/embassy-stm32/src/rcc/g0/mod.rs +++ b/embassy-stm32/src/rcc/g0/mod.rs @@ -102,10 +102,10 @@ impl Into for AHBPrescaler { /// Clocks configutation pub struct Config { - mux: ClockSrc, - ahb_pre: AHBPrescaler, - apb_pre: APBPrescaler, - low_power_run: bool, + pub mux: ClockSrc, + pub ahb_pre: AHBPrescaler, + pub apb_pre: APBPrescaler, + pub low_power_run: bool, } impl Default for Config { @@ -120,32 +120,6 @@ impl Default for Config { } } -impl Config { - #[inline] - pub fn clock_src(mut self, mux: ClockSrc) -> Self { - self.mux = mux; - self - } - - #[inline] - pub fn ahb_pre(mut self, pre: AHBPrescaler) -> Self { - self.ahb_pre = pre; - self - } - - #[inline] - pub fn apb_pre(mut self, pre: APBPrescaler) -> Self { - self.apb_pre = pre; - self - } - - #[inline] - pub fn low_power_run(mut self, on: bool) -> Self { - self.low_power_run = on; - self - } -} - /// RCC peripheral pub struct Rcc<'d> { _rb: peripherals::RCC, diff --git a/embassy-stm32/src/rcc/g4/mod.rs b/embassy-stm32/src/rcc/g4/mod.rs index 8dd37af8..8a75b2e0 100644 --- a/embassy-stm32/src/rcc/g4/mod.rs +++ b/embassy-stm32/src/rcc/g4/mod.rs @@ -74,11 +74,11 @@ impl Into for AHBPrescaler { /// Clocks configutation pub struct Config { - mux: ClockSrc, - ahb_pre: AHBPrescaler, - apb1_pre: APBPrescaler, - apb2_pre: APBPrescaler, - low_power_run: bool, + pub mux: ClockSrc, + pub ahb_pre: AHBPrescaler, + pub apb1_pre: APBPrescaler, + pub apb2_pre: APBPrescaler, + pub low_power_run: bool, } impl Default for Config { @@ -94,38 +94,6 @@ impl Default for Config { } } -impl Config { - #[inline] - pub fn clock_src(mut self, mux: ClockSrc) -> Self { - self.mux = mux; - self - } - - #[inline] - pub fn ahb_pre(mut self, pre: AHBPrescaler) -> Self { - self.ahb_pre = pre; - self - } - - #[inline] - pub fn apb1_pre(mut self, pre: APBPrescaler) -> Self { - self.apb1_pre = pre; - self - } - - #[inline] - pub fn apb2_pre(mut self, pre: APBPrescaler) -> Self { - self.apb2_pre = pre; - self - } - - #[inline] - pub fn low_power_run(mut self, on: bool) -> Self { - self.low_power_run = on; - self - } -} - /// RCC peripheral pub struct Rcc<'d> { _rb: peripherals::RCC, diff --git a/embassy-stm32/src/rcc/l0/mod.rs b/embassy-stm32/src/rcc/l0/mod.rs index 8af4eca0..fd84f09c 100644 --- a/embassy-stm32/src/rcc/l0/mod.rs +++ b/embassy-stm32/src/rcc/l0/mod.rs @@ -183,10 +183,10 @@ impl Into for MSIRange { /// Clocks configutation pub struct Config { - mux: ClockSrc, - ahb_pre: AHBPrescaler, - apb1_pre: APBPrescaler, - apb2_pre: APBPrescaler, + pub mux: ClockSrc, + pub ahb_pre: AHBPrescaler, + pub apb1_pre: APBPrescaler, + pub apb2_pre: APBPrescaler, } impl Default for Config { @@ -201,32 +201,6 @@ impl Default for Config { } } -impl Config { - #[inline] - pub fn clock_src(mut self, mux: ClockSrc) -> Self { - self.mux = mux; - self - } - - #[inline] - pub fn ahb_pre(mut self, pre: AHBPrescaler) -> Self { - self.ahb_pre = pre; - self - } - - #[inline] - pub fn apb1_pre(mut self, pre: APBPrescaler) -> Self { - self.apb1_pre = pre; - self - } - - #[inline] - pub fn apb2_pre(mut self, pre: APBPrescaler) -> Self { - self.apb2_pre = pre; - self - } -} - /// RCC peripheral pub struct Rcc<'d> { _rb: peripherals::RCC, diff --git a/embassy-stm32/src/rcc/l1/mod.rs b/embassy-stm32/src/rcc/l1/mod.rs index d0b52d2f..e46bee32 100644 --- a/embassy-stm32/src/rcc/l1/mod.rs +++ b/embassy-stm32/src/rcc/l1/mod.rs @@ -118,10 +118,10 @@ impl Into for MSIRange { /// Clocks configutation pub struct Config { - mux: ClockSrc, - ahb_pre: AHBPrescaler, - apb1_pre: APBPrescaler, - apb2_pre: APBPrescaler, + pub mux: ClockSrc, + pub ahb_pre: AHBPrescaler, + pub apb1_pre: APBPrescaler, + pub apb2_pre: APBPrescaler, } impl Default for Config { @@ -136,32 +136,6 @@ impl Default for Config { } } -impl Config { - #[inline] - pub fn clock_src(mut self, mux: ClockSrc) -> Self { - self.mux = mux; - self - } - - #[inline] - pub fn ahb_pre(mut self, pre: AHBPrescaler) -> Self { - self.ahb_pre = pre; - self - } - - #[inline] - pub fn apb1_pre(mut self, pre: APBPrescaler) -> Self { - self.apb1_pre = pre; - self - } - - #[inline] - pub fn apb2_pre(mut self, pre: APBPrescaler) -> Self { - self.apb2_pre = pre; - self - } -} - /// RCC peripheral pub struct Rcc<'d> { _rb: peripherals::RCC, diff --git a/embassy-stm32/src/rcc/l4/mod.rs b/embassy-stm32/src/rcc/l4/mod.rs index e1eadf85..a0eedf0b 100644 --- a/embassy-stm32/src/rcc/l4/mod.rs +++ b/embassy-stm32/src/rcc/l4/mod.rs @@ -269,10 +269,10 @@ impl Into for AHBPrescaler { /// Clocks configutation pub struct Config { - mux: ClockSrc, - ahb_pre: AHBPrescaler, - apb1_pre: APBPrescaler, - apb2_pre: APBPrescaler, + pub mux: ClockSrc, + pub ahb_pre: AHBPrescaler, + pub apb1_pre: APBPrescaler, + pub apb2_pre: APBPrescaler, } impl Default for Config { @@ -287,32 +287,6 @@ impl Default for Config { } } -impl Config { - #[inline] - pub fn clock_src(mut self, mux: ClockSrc) -> Self { - self.mux = mux; - self - } - - #[inline] - pub fn ahb_pre(mut self, pre: AHBPrescaler) -> Self { - self.ahb_pre = pre; - self - } - - #[inline] - pub fn apb1_pre(mut self, pre: APBPrescaler) -> Self { - self.apb1_pre = pre; - self - } - - #[inline] - pub fn apb2_pre(mut self, pre: APBPrescaler) -> Self { - self.apb2_pre = pre; - self - } -} - /// RCC peripheral pub struct Rcc<'d> { _rb: peripherals::RCC, diff --git a/embassy-stm32/src/rcc/u5/mod.rs b/embassy-stm32/src/rcc/u5/mod.rs index 6e68b220..a3df3a02 100644 --- a/embassy-stm32/src/rcc/u5/mod.rs +++ b/embassy-stm32/src/rcc/u5/mod.rs @@ -274,16 +274,16 @@ impl Default for MSIRange { #[derive(Copy, Clone)] pub struct Config { - mux: ClockSrc, - ahb_pre: AHBPrescaler, - apb1_pre: APBPrescaler, - apb2_pre: APBPrescaler, - apb3_pre: APBPrescaler, + pub mux: ClockSrc, + pub ahb_pre: AHBPrescaler, + pub apb1_pre: APBPrescaler, + pub apb2_pre: APBPrescaler, + pub apb3_pre: APBPrescaler, } -impl Config { - pub fn new() -> Self { - Config { +impl Default for Config { + fn default() -> Self { + Self { mux: ClockSrc::MSI(MSIRange::default()), ahb_pre: Default::default(), apb1_pre: Default::default(), @@ -293,12 +293,6 @@ impl Config { } } -impl Default for Config { - fn default() -> Self { - Config::new() - } -} - /// Extension trait that freezes the `RCC` peripheral with provided clocks configuration pub trait RccExt { fn freeze(self, config: Config, power: &Power) -> Clocks; diff --git a/embassy-stm32/src/rcc/wb/mod.rs b/embassy-stm32/src/rcc/wb/mod.rs index 43535741..73835cac 100644 --- a/embassy-stm32/src/rcc/wb/mod.rs +++ b/embassy-stm32/src/rcc/wb/mod.rs @@ -86,10 +86,10 @@ impl Into for AHBPrescaler { /// Clocks configutation pub struct Config { - mux: ClockSrc, - ahb_pre: AHBPrescaler, - apb1_pre: APBPrescaler, - apb2_pre: APBPrescaler, + pub mux: ClockSrc, + pub ahb_pre: AHBPrescaler, + pub apb1_pre: APBPrescaler, + pub apb2_pre: APBPrescaler, } impl Default for Config { @@ -104,32 +104,6 @@ impl Default for Config { } } -impl Config { - #[inline] - pub fn clock_src(mut self, mux: ClockSrc) -> Self { - self.mux = mux; - self - } - - #[inline] - pub fn ahb_pre(mut self, pre: AHBPrescaler) -> Self { - self.ahb_pre = pre; - self - } - - #[inline] - pub fn apb1_pre(mut self, pre: APBPrescaler) -> Self { - self.apb1_pre = pre; - self - } - - #[inline] - pub fn apb2_pre(mut self, pre: APBPrescaler) -> Self { - self.apb2_pre = pre; - self - } -} - /// RCC peripheral pub struct Rcc<'d> { _rb: peripherals::RCC, diff --git a/embassy-stm32/src/rcc/wl5x/mod.rs b/embassy-stm32/src/rcc/wl5x/mod.rs index aa49c99c..1b7bfb09 100644 --- a/embassy-stm32/src/rcc/wl5x/mod.rs +++ b/embassy-stm32/src/rcc/wl5x/mod.rs @@ -87,10 +87,10 @@ impl Into for AHBPrescaler { /// Clocks configutation pub struct Config { - mux: ClockSrc, - ahb_pre: AHBPrescaler, - apb1_pre: APBPrescaler, - apb2_pre: APBPrescaler, + pub mux: ClockSrc, + pub ahb_pre: AHBPrescaler, + pub apb1_pre: APBPrescaler, + pub apb2_pre: APBPrescaler, } impl Default for Config { @@ -105,32 +105,6 @@ impl Default for Config { } } -impl Config { - #[inline] - pub fn clock_src(mut self, mux: ClockSrc) -> Self { - self.mux = mux; - self - } - - #[inline] - pub fn ahb_pre(mut self, pre: AHBPrescaler) -> Self { - self.ahb_pre = pre; - self - } - - #[inline] - pub fn apb1_pre(mut self, pre: APBPrescaler) -> Self { - self.apb1_pre = pre; - self - } - - #[inline] - pub fn apb2_pre(mut self, pre: APBPrescaler) -> Self { - self.apb2_pre = pre; - self - } -} - /// RCC peripheral pub struct Rcc<'d> { _rb: peripherals::RCC, diff --git a/examples/stm32l0/src/bin/lorawan.rs b/examples/stm32l0/src/bin/lorawan.rs index cbae8835..7ce859a8 100644 --- a/examples/stm32l0/src/bin/lorawan.rs +++ b/examples/stm32l0/src/bin/lorawan.rs @@ -25,7 +25,7 @@ use lorawan_encoding::default_crypto::DefaultFactory as Crypto; fn config() -> embassy_stm32::Config { let mut config = embassy_stm32::Config::default(); - config.rcc = config.rcc.clock_src(embassy_stm32::rcc::ClockSrc::HSI16); + config.rcc.mux = embassy_stm32::rcc::ClockSrc::HSI16; config } diff --git a/examples/stm32l4/src/bin/rng.rs b/examples/stm32l4/src/bin/rng.rs index ee5f579f..c60b1d8b 100644 --- a/examples/stm32l4/src/bin/rng.rs +++ b/examples/stm32l4/src/bin/rng.rs @@ -14,13 +14,13 @@ use example_common::*; fn config() -> Config { let mut config = Config::default(); - config.rcc = config.rcc.clock_src(ClockSrc::PLL( + config.rcc.mux = ClockSrc::PLL( PLLSource::HSI16, PLLClkDiv::Div2, PLLSrcDiv::Div1, PLLMul::Mul8, Some(PLLClkDiv::Div2), - )); + ); config } diff --git a/examples/stm32wl55/src/bin/lorawan.rs b/examples/stm32wl55/src/bin/lorawan.rs index 155905ae..7048a581 100644 --- a/examples/stm32wl55/src/bin/lorawan.rs +++ b/examples/stm32wl55/src/bin/lorawan.rs @@ -23,7 +23,7 @@ use lorawan_encoding::default_crypto::DefaultFactory as Crypto; fn config() -> embassy_stm32::Config { let mut config = embassy_stm32::Config::default(); - config.rcc = config.rcc.clock_src(embassy_stm32::rcc::ClockSrc::HSI16); + config.rcc.mux = embassy_stm32::rcc::ClockSrc::HSI16; config } diff --git a/examples/stm32wl55/src/bin/subghz.rs b/examples/stm32wl55/src/bin/subghz.rs index 89549c76..a73c361c 100644 --- a/examples/stm32wl55/src/bin/subghz.rs +++ b/examples/stm32wl55/src/bin/subghz.rs @@ -66,7 +66,7 @@ const TX_PARAMS: TxParams = TxParams::new() fn config() -> embassy_stm32::Config { let mut config = embassy_stm32::Config::default(); - config.rcc = config.rcc.clock_src(embassy_stm32::rcc::ClockSrc::HSE32); + config.rcc.mux = embassy_stm32::rcc::ClockSrc::HSE32; config } From 5d2f40b337da8bd6af93425d8a1dcc9229fe1f6d Mon Sep 17 00:00:00 2001 From: Dario Nieuwenhuis Date: Tue, 4 Jan 2022 11:20:37 +0100 Subject: [PATCH 2/3] stm32wl/rcc: remove unneded gpio enables in RCC. These are already done by gpio::init(). --- embassy-stm32/src/rcc/wl5x/mod.rs | 7 ------- 1 file changed, 7 deletions(-) diff --git a/embassy-stm32/src/rcc/wl5x/mod.rs b/embassy-stm32/src/rcc/wl5x/mod.rs index 1b7bfb09..edf603ee 100644 --- a/embassy-stm32/src/rcc/wl5x/mod.rs +++ b/embassy-stm32/src/rcc/wl5x/mod.rs @@ -231,13 +231,6 @@ impl RccExt for RCC { pub unsafe fn init(config: Config) { let r = ::steal(); - let rcc = pac::RCC; - rcc.ahb2enr().write(|w| { - w.set_gpioaen(true); - w.set_gpioben(true); - w.set_gpiocen(true); - w.set_gpiohen(true); - }); let clocks = r.freeze(config); set_freqs(clocks); } From 89b009b11d7c45533f53a41c6586ba514cf7be58 Mon Sep 17 00:00:00 2001 From: Dario Nieuwenhuis Date: Tue, 4 Jan 2022 11:22:08 +0100 Subject: [PATCH 3/3] stm32h7/rcc: remove unneeded DMA enable settings. These are automatically enabled by dma::init(). --- embassy-stm32/src/rcc/h7/mod.rs | 10 ---------- examples/stm32h7/src/bin/camera.rs | 2 -- examples/stm32h7/src/example_common.rs | 1 - 3 files changed, 13 deletions(-) diff --git a/embassy-stm32/src/rcc/h7/mod.rs b/embassy-stm32/src/rcc/h7/mod.rs index be7f440a..cd493a80 100644 --- a/embassy-stm32/src/rcc/h7/mod.rs +++ b/embassy-stm32/src/rcc/h7/mod.rs @@ -72,8 +72,6 @@ pub struct Config { pub pll1: PllConfig, pub pll2: PllConfig, pub pll3: PllConfig, - pub enable_dma1: bool, - pub enable_dma2: bool, } pub struct Rcc<'d> { @@ -331,14 +329,6 @@ impl<'d> Rcc<'d> { }); while !SYSCFG.cccsr().read().ready() {} - if self.config.enable_dma1 { - RCC.ahb1enr().modify(|w| w.set_dma1en(true)); - } - - if self.config.enable_dma2 { - RCC.ahb1enr().modify(|w| w.set_dma2en(true)); - } - CoreClocks { hclk: Hertz(rcc_hclk), pclk1: Hertz(rcc_pclk1), diff --git a/examples/stm32h7/src/bin/camera.rs b/examples/stm32h7/src/bin/camera.rs index 2fa742b8..d9459207 100644 --- a/examples/stm32h7/src/bin/camera.rs +++ b/examples/stm32h7/src/bin/camera.rs @@ -34,8 +34,6 @@ pub fn config() -> Config { config.rcc.sys_ck = Some(400.mhz().into()); config.rcc.hclk = Some(400.mhz().into()); config.rcc.pll1.q_ck = Some(100.mhz().into()); - config.rcc.enable_dma1 = true; - config.rcc.enable_dma2 = true; config.rcc.pclk1 = Some(100.mhz().into()); config.rcc.pclk2 = Some(100.mhz().into()); config.rcc.pclk3 = Some(100.mhz().into()); diff --git a/examples/stm32h7/src/example_common.rs b/examples/stm32h7/src/example_common.rs index 2e26730f..524bee6d 100644 --- a/examples/stm32h7/src/example_common.rs +++ b/examples/stm32h7/src/example_common.rs @@ -23,6 +23,5 @@ pub fn config() -> Config { let mut config = Config::default(); config.rcc.sys_ck = Some(400.mhz().into()); config.rcc.pll1.q_ck = Some(100.mhz().into()); - config.rcc.enable_dma1 = true; config }