diff --git a/embassy-stm32/src/lib.rs b/embassy-stm32/src/lib.rs index 0567aa72..eb893353 100644 --- a/embassy-stm32/src/lib.rs +++ b/embassy-stm32/src/lib.rs @@ -67,14 +67,7 @@ pub use generated::{peripherals, Peripherals}; #[non_exhaustive] pub struct Config { - rcc: rcc::Config, -} - -impl Config { - pub fn rcc(mut self, rcc: rcc::Config) -> Self { - self.rcc = rcc; - self - } + pub rcc: rcc::Config, } impl Default for Config { diff --git a/embassy-stm32/src/rcc/h7/mod.rs b/embassy-stm32/src/rcc/h7/mod.rs index 70632f28..5ec53182 100644 --- a/embassy-stm32/src/rcc/h7/mod.rs +++ b/embassy-stm32/src/rcc/h7/mod.rs @@ -70,83 +70,6 @@ pub struct Config { pub pll3: PllConfig, } -impl Config { - pub fn sys_ck>(mut self, freq: T) -> Self { - self.sys_ck = Some(freq.into()); - self - } - - pub fn per_ck>(mut self, freq: T) -> Self { - self.per_ck = Some(freq.into()); - self - } - - pub fn pclk1>(mut self, freq: T) -> Self { - self.pclk1 = Some(freq.into()); - self - } - - pub fn pclk2>(mut self, freq: T) -> Self { - self.pclk2 = Some(freq.into()); - self - } - - pub fn pclk3>(mut self, freq: T) -> Self { - self.pclk3 = Some(freq.into()); - self - } - - pub fn pclk4>(mut self, freq: T) -> Self { - self.pclk4 = Some(freq.into()); - self - } - - pub fn pll1_p>(mut self, freq: T) -> Self { - self.pll1.p_ck = Some(freq.into()); - self - } - - pub fn pll1_q>(mut self, freq: T) -> Self { - self.pll1.q_ck = Some(freq.into()); - self - } - - pub fn pll1_r>(mut self, freq: T) -> Self { - self.pll1.r_ck = Some(freq.into()); - self - } - - pub fn pll2_p>(mut self, freq: T) -> Self { - self.pll2.p_ck = Some(freq.into()); - self - } - - pub fn pll2_q>(mut self, freq: T) -> Self { - self.pll2.q_ck = Some(freq.into()); - self - } - - pub fn pll2_r>(mut self, freq: T) -> Self { - self.pll2.r_ck = Some(freq.into()); - self - } - - pub fn pll3_p>(mut self, freq: T) -> Self { - self.pll3.p_ck = Some(freq.into()); - self - } - - pub fn pll3_q>(mut self, freq: T) -> Self { - self.pll3.q_ck = Some(freq.into()); - self - } - - pub fn pll3_r>(mut self, freq: T) -> Self { - self.pll3.r_ck = Some(freq.into()); - self - } -} - pub struct Rcc<'d> { inner: PhantomData<&'d ()>, config: Config, diff --git a/examples/stm32f0/src/example_common.rs b/examples/stm32f0/src/example_common.rs index e0ba4cd0..c166522e 100644 --- a/examples/stm32f0/src/example_common.rs +++ b/examples/stm32f0/src/example_common.rs @@ -12,7 +12,9 @@ use embassy_stm32::Config; pub fn config() -> Config { let mut rcc_config = rcc::Config::default(); rcc_config.enable_debug_wfe = true; - Config::default().rcc(rcc_config) + let mut config = Config::default(); + config.rcc = rcc_config; + config } defmt::timestamp! {"{=u64}", { diff --git a/examples/stm32f4/src/bin/hello.rs b/examples/stm32f4/src/bin/hello.rs index 8ee6c1ef..8cbd46d6 100644 --- a/examples/stm32f4/src/bin/hello.rs +++ b/examples/stm32f4/src/bin/hello.rs @@ -22,7 +22,9 @@ fn config() -> Config { rcc_config.sys_ck = Some(Hertz(84_000_000)); rcc_config.enable_debug_wfe = true; - Config::default().rcc(rcc_config) + let mut config = Config::default(); + config.rcc = rcc_config; + config } #[embassy::main(config = "config()")] diff --git a/examples/stm32h7/src/bin/dac.rs b/examples/stm32h7/src/bin/dac.rs index 658449f1..fb2feb7b 100644 --- a/examples/stm32h7/src/bin/dac.rs +++ b/examples/stm32h7/src/bin/dac.rs @@ -22,9 +22,7 @@ use embassy_stm32::Config; fn main() -> ! { info!("Hello World, dude!"); - let p = embassy_stm32::init( - Config::default().rcc(rcc::Config::default().sys_ck(400.mhz()).pll1_q(100.mhz())), - ); + let p = embassy_stm32::init( config() ); unsafe { Dbgmcu::enable_all(); @@ -54,3 +52,16 @@ fn to_sine_wave(v: u8) -> u8 { (r.sin() * 128.0 + 127.0) as u8 } } + +fn config() -> Config { + let mut config = Config::default(); + config.rcc = rcc_config(); + config +} + +fn rcc_config() -> rcc::Config { + let mut config = rcc::Config::default(); + config.sys_ck = Some(400.mhz().into()); + config.pll1.q_ck = Some( 100.mhz().into() ); + config +} \ No newline at end of file diff --git a/examples/stm32h7/src/bin/eth.rs b/examples/stm32h7/src/bin/eth.rs index e49a101b..233c5e4c 100644 --- a/examples/stm32h7/src/bin/eth.rs +++ b/examples/stm32h7/src/bin/eth.rs @@ -22,9 +22,10 @@ use embassy_net::{ use embassy_stm32::clock::{Alarm, Clock}; use embassy_stm32::eth::lan8742a::LAN8742A; use embassy_stm32::eth::{Ethernet, State}; -use embassy_stm32::rcc::{Config as RccConfig, Rcc}; +use embassy_stm32::rcc::{self, Rcc}; use embassy_stm32::rng::Random; use embassy_stm32::time::Hertz; +use embassy_stm32::time::U32Ext; use embassy_stm32::{interrupt, peripherals, Config}; use heapless::Vec; use panic_probe as _; @@ -108,16 +109,11 @@ fn main() -> ! { info!("Hello World!"); info!("Setup RCC..."); - let mut rcc_config = RccConfig::default(); - rcc_config.sys_ck = Some(Hertz(400_000_000)); - rcc_config.pll1.q_ck = Some(Hertz(100_000_000)); - let config = Config::default().rcc(rcc_config); - - let mut p = embassy_stm32::init(config); + let mut p = embassy_stm32::init(config()); // Constrain and Freeze clock - let mut rcc = Rcc::new(&mut p.RCC, RccConfig::default()); + let mut rcc = Rcc::new(&mut p.RCC, rcc::Config::default()); rcc.enable_debug_wfe(&mut p.DBGMCU, true); let rtc_int = interrupt_take!(TIM2); @@ -157,3 +153,16 @@ fn main() -> ! { unwrap!(spawner.spawn(main_task(eth, config, spawner))); }) } + +fn config() -> Config { + let mut config = Config::default(); + config.rcc = rcc_config(); + config +} + +fn rcc_config() -> rcc::Config { + let mut config = rcc::Config::default(); + config.sys_ck = Some(400.mhz().into()); + config.pll1.q_ck = Some( 100.mhz().into() ); + config +} \ No newline at end of file diff --git a/examples/stm32h7/src/bin/spi.rs b/examples/stm32h7/src/bin/spi.rs index 3ae2ae7d..b2cf1961 100644 --- a/examples/stm32h7/src/bin/spi.rs +++ b/examples/stm32h7/src/bin/spi.rs @@ -60,9 +60,7 @@ fn main() -> ! { Dbgmcu::enable_all(); } - let p = embassy_stm32::init( - Config::default().rcc(rcc::Config::default().sys_ck(400.mhz()).pll1_q(100.mhz())), - ); + let p = embassy_stm32::init( config() ); let spi = spi::Spi::new( p.SPI3, @@ -82,3 +80,16 @@ fn main() -> ! { unwrap!(spawner.spawn(main_task(spi))); }) } + +fn config() -> Config { + let mut config = Config::default(); + config.rcc = rcc_config(); + config +} + +fn rcc_config() -> rcc::Config { + let mut config = rcc::Config::default(); + config.sys_ck = Some(400.mhz().into()); + config.pll1.q_ck = Some( 100.mhz().into() ); + config +} \ No newline at end of file diff --git a/examples/stm32h7/src/bin/spi_dma.rs b/examples/stm32h7/src/bin/spi_dma.rs index 17cc98f9..0ce4212b 100644 --- a/examples/stm32h7/src/bin/spi_dma.rs +++ b/examples/stm32h7/src/bin/spi_dma.rs @@ -8,6 +8,7 @@ #[path = "../example_common.rs"] mod example_common; + use core::fmt::Write; use embassy::executor::Executor; use embassy::time::Clock; @@ -55,9 +56,7 @@ fn main() -> ! { Dbgmcu::enable_all(); } - let p = embassy_stm32::init( - Config::default().rcc(rcc::Config::default().sys_ck(400.mhz()).pll1_q(100.mhz())), - ); + let p = embassy_stm32::init( config() ); let spi = spi::Spi::new( p.SPI3, @@ -77,3 +76,16 @@ fn main() -> ! { unwrap!(spawner.spawn(main_task(spi))); }) } + +fn config() -> Config { + let mut config = Config::default(); + config.rcc = rcc_config(); + config +} + +fn rcc_config() -> rcc::Config { + let mut config = rcc::Config::default(); + config.sys_ck = Some(400.mhz().into()); + config.pll1.q_ck = Some( 100.mhz().into() ); + config +}