From 2e85eaf7d5f4dcf6d84f426542b8ec87aa51c429 Mon Sep 17 00:00:00 2001 From: Dario Nieuwenhuis Date: Wed, 17 Aug 2022 22:25:58 +0200 Subject: [PATCH] examples Remove the `fn config()` idiom. It was only useful for doing #[embassy_executor::main(config = "config()")]`. Now that it's gone, it makes more sense to build the config in main directly. --- examples/stm32f1/src/bin/hello.rs | 11 +++----- examples/stm32f1/src/bin/usb_serial.rs | 9 +++---- examples/stm32f2/src/bin/pll.rs | 13 +++++---- examples/stm32f3/src/bin/hello.rs | 9 +++---- examples/stm32f3/src/bin/usb_serial.rs | 11 +++----- examples/stm32f4/src/bin/hello.rs | 11 +++----- examples/stm32f4/src/bin/sdmmc.rs | 10 +++---- examples/stm32f7/src/bin/eth.rs | 11 +++----- examples/stm32f7/src/bin/hello.rs | 11 +++----- examples/stm32f7/src/bin/sdmmc.rs | 11 +++----- examples/stm32h7/src/bin/adc.rs | 9 +++---- examples/stm32h7/src/bin/camera.rs | 27 ++++++++----------- examples/stm32h7/src/bin/dac.rs | 14 ++++------ examples/stm32h7/src/bin/eth.rs | 10 +++---- examples/stm32h7/src/bin/eth_client.rs | 10 +++---- examples/stm32h7/src/bin/fmc.rs | 9 +++---- .../stm32h7/src/bin/low_level_timer_api.rs | 9 +++---- examples/stm32h7/src/bin/pwm.rs | 10 +++---- examples/stm32h7/src/bin/sdmmc.rs | 10 +++---- examples/stm32h7/src/bin/spi.rs | 14 ++++------ examples/stm32h7/src/bin/spi_dma.rs | 14 ++++------ examples/stm32l0/src/bin/button_exti.rs | 12 ++++----- examples/stm32l0/src/bin/lorawan.rs | 9 +++---- examples/stm32l4/src/bin/rng.rs | 9 +++---- examples/stm32l5/src/bin/rng.rs | 9 +++---- examples/stm32l5/src/bin/usb_ethernet.rs | 16 ++++------- examples/stm32l5/src/bin/usb_hid_mouse.rs | 16 ++++------- examples/stm32l5/src/bin/usb_serial.rs | 16 ++++------- examples/stm32wl/src/bin/lorawan.rs | 9 +++---- examples/stm32wl/src/bin/subghz.rs | 11 +++----- 30 files changed, 121 insertions(+), 229 deletions(-) diff --git a/examples/stm32f1/src/bin/hello.rs b/examples/stm32f1/src/bin/hello.rs index 721b21c36..57892d3cc 100644 --- a/examples/stm32f1/src/bin/hello.rs +++ b/examples/stm32f1/src/bin/hello.rs @@ -9,15 +9,12 @@ use embassy_stm32::time::Hertz; use embassy_stm32::Config; use {defmt_rtt as _, panic_probe as _}; -fn config() -> Config { - let mut config = Config::default(); - config.rcc.sys_ck = Some(Hertz(36_000_000)); - config -} - #[embassy_executor::main] async fn main(_spawner: Spawner) -> ! { - let _p = embassy_stm32::init(config()); + let mut config = Config::default(); + config.rcc.sys_ck = Some(Hertz(36_000_000)); + let _p = embassy_stm32::init(config); + loop { info!("Hello World!"); Timer::after(Duration::from_secs(1)).await; diff --git a/examples/stm32f1/src/bin/usb_serial.rs b/examples/stm32f1/src/bin/usb_serial.rs index 7f27e6251..2301c51b6 100644 --- a/examples/stm32f1/src/bin/usb_serial.rs +++ b/examples/stm32f1/src/bin/usb_serial.rs @@ -15,17 +15,14 @@ use embassy_usb_serial::{CdcAcmClass, State}; use futures::future::join; use {defmt_rtt as _, panic_probe as _}; -fn config() -> Config { +#[embassy_executor::main] +async fn main(_spawner: Spawner) { let mut config = Config::default(); config.rcc.hse = Some(Hertz(8_000_000)); config.rcc.sys_ck = Some(Hertz(48_000_000)); config.rcc.pclk1 = Some(Hertz(24_000_000)); - config -} + let mut p = embassy_stm32::init(config); -#[embassy_executor::main] -async fn main(_spawner: Spawner) { - let mut p = embassy_stm32::init(config()); info!("Hello World!"); { diff --git a/examples/stm32f2/src/bin/pll.rs b/examples/stm32f2/src/bin/pll.rs index bc0c160ba..6fce7a716 100644 --- a/examples/stm32f2/src/bin/pll.rs +++ b/examples/stm32f2/src/bin/pll.rs @@ -14,8 +14,10 @@ use embassy_stm32::time::Hertz; use embassy_stm32::Config; use {defmt_rtt as _, panic_probe as _}; -// Example config for maximum performance on a NUCLEO-F207ZG board -fn config() -> Config { +#[embassy_executor::main] +async fn main(_spawner: Spawner) { + // Example config for maximum performance on a NUCLEO-F207ZG board + let mut config = Config::default(); // By default, HSE on the board comes from a 8 MHz clock signal (not a crystal) config.rcc.hse = Some(HSEConfig { @@ -40,12 +42,9 @@ fn config() -> Config { config.rcc.apb1_pre = APBPrescaler::Div4; // 120 MHz / 2 = 60 MHz APB2 frequency config.rcc.apb2_pre = APBPrescaler::Div2; - config -} -#[embassy_executor::main] -async fn main(_spawner: Spawner) { - let _p = embassy_stm32::init(config()); + let _p = embassy_stm32::init(config); + loop { Timer::after(Duration::from_millis(1000)).await; info!("1s elapsed"); diff --git a/examples/stm32f3/src/bin/hello.rs b/examples/stm32f3/src/bin/hello.rs index 7846912c9..cd59f7409 100644 --- a/examples/stm32f3/src/bin/hello.rs +++ b/examples/stm32f3/src/bin/hello.rs @@ -9,16 +9,13 @@ use embassy_stm32::time::Hertz; use embassy_stm32::Config; use {defmt_rtt as _, panic_probe as _}; -fn config() -> Config { +#[embassy_executor::main] +async fn main(_spawner: Spawner) -> ! { let mut config = Config::default(); config.rcc.hse = Some(Hertz(8_000_000)); config.rcc.sysclk = Some(Hertz(16_000_000)); - config -} + let _p = embassy_stm32::init(config); -#[embassy_executor::main] -async fn main(_spawner: Spawner) -> ! { - let _p = embassy_stm32::init(config()); loop { info!("Hello World!"); Timer::after(Duration::from_secs(1)).await; diff --git a/examples/stm32f3/src/bin/usb_serial.rs b/examples/stm32f3/src/bin/usb_serial.rs index 36d38d87f..757643ea5 100644 --- a/examples/stm32f3/src/bin/usb_serial.rs +++ b/examples/stm32f3/src/bin/usb_serial.rs @@ -15,21 +15,16 @@ use embassy_usb_serial::{CdcAcmClass, State}; use futures::future::join; use {defmt_rtt as _, panic_probe as _}; -fn config() -> Config { +#[embassy_executor::main] +async fn main(_spawner: Spawner) { let mut config = Config::default(); - config.rcc.hse = Some(mhz(8)); config.rcc.sysclk = Some(mhz(48)); config.rcc.pclk1 = Some(mhz(24)); config.rcc.pclk2 = Some(mhz(24)); config.rcc.pll48 = true; + let p = embassy_stm32::init(config); - config -} - -#[embassy_executor::main] -async fn main(_spawner: Spawner) { - let p = embassy_stm32::init(config()); info!("Hello World!"); // Needed for nucleo-stm32f303ze diff --git a/examples/stm32f4/src/bin/hello.rs b/examples/stm32f4/src/bin/hello.rs index 6facb9bb7..26d3555a2 100644 --- a/examples/stm32f4/src/bin/hello.rs +++ b/examples/stm32f4/src/bin/hello.rs @@ -9,15 +9,12 @@ use embassy_stm32::time::Hertz; use embassy_stm32::Config; use {defmt_rtt as _, panic_probe as _}; -fn config() -> Config { - let mut config = Config::default(); - config.rcc.sys_ck = Some(Hertz(84_000_000)); - config -} - #[embassy_executor::main] async fn main(_spawner: Spawner) -> ! { - let _p = embassy_stm32::init(config()); + let mut config = Config::default(); + config.rcc.sys_ck = Some(Hertz(84_000_000)); + let _p = embassy_stm32::init(config); + loop { info!("Hello World!"); Timer::after(Duration::from_secs(1)).await; diff --git a/examples/stm32f4/src/bin/sdmmc.rs b/examples/stm32f4/src/bin/sdmmc.rs index 996694f2c..b8e56d2e1 100644 --- a/examples/stm32f4/src/bin/sdmmc.rs +++ b/examples/stm32f4/src/bin/sdmmc.rs @@ -9,15 +9,11 @@ use embassy_stm32::time::mhz; use embassy_stm32::{interrupt, Config}; use {defmt_rtt as _, panic_probe as _}; -fn config() -> Config { - let mut config = Config::default(); - config.rcc.sys_ck = Some(mhz(48)); - config -} - #[embassy_executor::main] async fn main(_spawner: Spawner) -> ! { - let p = embassy_stm32::init(config()); + let mut config = Config::default(); + config.rcc.sys_ck = Some(mhz(48)); + let p = embassy_stm32::init(config); info!("Hello World!"); let irq = interrupt::take!(SDIO); diff --git a/examples/stm32f7/src/bin/eth.rs b/examples/stm32f7/src/bin/eth.rs index f8904fa03..1ec30353d 100644 --- a/examples/stm32f7/src/bin/eth.rs +++ b/examples/stm32f7/src/bin/eth.rs @@ -33,15 +33,12 @@ async fn net_task(stack: &'static Stack) -> ! { stack.run().await } -fn config() -> Config { - let mut config = Config::default(); - config.rcc.sys_ck = Some(mhz(200)); - config -} - #[embassy_executor::main] async fn main(spawner: Spawner) -> ! { - let p = embassy_stm32::init(config()); + let mut config = Config::default(); + config.rcc.sys_ck = Some(mhz(200)); + let p = embassy_stm32::init(config); + info!("Hello World!"); // Generate random seed. diff --git a/examples/stm32f7/src/bin/hello.rs b/examples/stm32f7/src/bin/hello.rs index 6facb9bb7..26d3555a2 100644 --- a/examples/stm32f7/src/bin/hello.rs +++ b/examples/stm32f7/src/bin/hello.rs @@ -9,15 +9,12 @@ use embassy_stm32::time::Hertz; use embassy_stm32::Config; use {defmt_rtt as _, panic_probe as _}; -fn config() -> Config { - let mut config = Config::default(); - config.rcc.sys_ck = Some(Hertz(84_000_000)); - config -} - #[embassy_executor::main] async fn main(_spawner: Spawner) -> ! { - let _p = embassy_stm32::init(config()); + let mut config = Config::default(); + config.rcc.sys_ck = Some(Hertz(84_000_000)); + let _p = embassy_stm32::init(config); + loop { info!("Hello World!"); Timer::after(Duration::from_secs(1)).await; diff --git a/examples/stm32f7/src/bin/sdmmc.rs b/examples/stm32f7/src/bin/sdmmc.rs index 975c5b91f..9d97a1de4 100644 --- a/examples/stm32f7/src/bin/sdmmc.rs +++ b/examples/stm32f7/src/bin/sdmmc.rs @@ -9,15 +9,12 @@ use embassy_stm32::time::mhz; use embassy_stm32::{interrupt, Config}; use {defmt_rtt as _, panic_probe as _}; -fn config() -> Config { - let mut config = Config::default(); - config.rcc.sys_ck = Some(mhz(200)); - config -} - #[embassy_executor::main] async fn main(_spawner: Spawner) -> ! { - let p = embassy_stm32::init(config()); + let mut config = Config::default(); + config.rcc.sys_ck = Some(mhz(200)); + let p = embassy_stm32::init(config); + info!("Hello World!"); let irq = interrupt::take!(SDMMC1); diff --git a/examples/stm32h7/src/bin/adc.rs b/examples/stm32h7/src/bin/adc.rs index 96457e766..0715a0f62 100644 --- a/examples/stm32h7/src/bin/adc.rs +++ b/examples/stm32h7/src/bin/adc.rs @@ -11,18 +11,15 @@ use embassy_stm32::time::mhz; use embassy_stm32::Config; use {defmt_rtt as _, panic_probe as _}; -pub fn config() -> Config { +#[embassy_executor::main] +async fn main(_spawner: Spawner) { let mut config = Config::default(); config.rcc.sys_ck = Some(mhz(400)); config.rcc.hclk = Some(mhz(200)); config.rcc.per_ck = Some(mhz(64)); config.rcc.adc_clock_source = AdcClockSource::PerCk; - config -} + let mut p = embassy_stm32::init(config); -#[embassy_executor::main] -async fn main(_spawner: Spawner) { - let mut p = embassy_stm32::init(config()); info!("Hello World!"); let mut adc = Adc::new(p.ADC3, &mut Delay); diff --git a/examples/stm32h7/src/bin/camera.rs b/examples/stm32h7/src/bin/camera.rs index 8e93a54c8..a281e75c9 100644 --- a/examples/stm32h7/src/bin/camera.rs +++ b/examples/stm32h7/src/bin/camera.rs @@ -10,22 +10,8 @@ use embassy_stm32::i2c::I2c; use embassy_stm32::rcc::{Mco, Mco1Source, McoClock}; use embassy_stm32::time::{khz, mhz}; use embassy_stm32::{interrupt, Config}; -use {defmt_rtt as _, panic_probe as _}; - -#[allow(unused)] -pub fn config() -> Config { - let mut config = Config::default(); - config.rcc.sys_ck = Some(mhz(400)); - config.rcc.hclk = Some(mhz(400)); - config.rcc.pll1.q_ck = Some(mhz(100)); - config.rcc.pclk1 = Some(mhz(100)); - config.rcc.pclk2 = Some(mhz(100)); - config.rcc.pclk3 = Some(mhz(100)); - config.rcc.pclk4 = Some(mhz(100)); - config -} - use ov7725::*; +use {defmt_rtt as _, panic_probe as _}; const WIDTH: usize = 100; const HEIGHT: usize = 100; @@ -34,7 +20,16 @@ static mut FRAME: [u32; WIDTH * HEIGHT / 2] = [0u32; WIDTH * HEIGHT / 2]; #[embassy_executor::main] async fn main(_spawner: Spawner) { - let p = embassy_stm32::init(config()); + let mut config = Config::default(); + config.rcc.sys_ck = Some(mhz(400)); + config.rcc.hclk = Some(mhz(400)); + config.rcc.pll1.q_ck = Some(mhz(100)); + config.rcc.pclk1 = Some(mhz(100)); + config.rcc.pclk2 = Some(mhz(100)); + config.rcc.pclk3 = Some(mhz(100)); + config.rcc.pclk4 = Some(mhz(100)); + let p = embassy_stm32::init(config); + defmt::info!("Hello World!"); let mco = Mco::new(p.MCO1, p.PA8, Mco1Source::Hsi, McoClock::Divided(3)); diff --git a/examples/stm32h7/src/bin/dac.rs b/examples/stm32h7/src/bin/dac.rs index dece74bba..f12716370 100644 --- a/examples/stm32h7/src/bin/dac.rs +++ b/examples/stm32h7/src/bin/dac.rs @@ -9,19 +9,15 @@ use embassy_stm32::time::mhz; use embassy_stm32::Config; use {defmt_rtt as _, panic_probe as _}; -pub fn config() -> Config { - let mut config = Config::default(); - config.rcc.sys_ck = Some(mhz(400)); - config.rcc.hclk = Some(mhz(200)); - config.rcc.pll1.q_ck = Some(mhz(100)); - config -} - #[entry] fn main() -> ! { info!("Hello World, dude!"); - let p = embassy_stm32::init(config()); + let mut config = Config::default(); + config.rcc.sys_ck = Some(mhz(400)); + config.rcc.hclk = Some(mhz(200)); + config.rcc.pll1.q_ck = Some(mhz(100)); + let p = embassy_stm32::init(config); let mut dac = Dac::new_1ch(p.DAC1, p.PA4); diff --git a/examples/stm32h7/src/bin/eth.rs b/examples/stm32h7/src/bin/eth.rs index 7ad2f52c7..9039b7ee7 100644 --- a/examples/stm32h7/src/bin/eth.rs +++ b/examples/stm32h7/src/bin/eth.rs @@ -33,17 +33,13 @@ async fn net_task(stack: &'static Stack) -> ! { stack.run().await } -pub fn config() -> Config { +#[embassy_executor::main] +async fn main(spawner: Spawner) -> ! { let mut config = Config::default(); config.rcc.sys_ck = Some(mhz(400)); config.rcc.hclk = Some(mhz(200)); config.rcc.pll1.q_ck = Some(mhz(100)); - config -} - -#[embassy_executor::main] -async fn main(spawner: Spawner) -> ! { - let p = embassy_stm32::init(config()); + let p = embassy_stm32::init(config); info!("Hello World!"); // Generate random seed. diff --git a/examples/stm32h7/src/bin/eth_client.rs b/examples/stm32h7/src/bin/eth_client.rs index 736a2992e..25e75d71e 100644 --- a/examples/stm32h7/src/bin/eth_client.rs +++ b/examples/stm32h7/src/bin/eth_client.rs @@ -34,17 +34,13 @@ async fn net_task(stack: &'static Stack) -> ! { stack.run().await } -pub fn config() -> Config { +#[embassy_executor::main] +async fn main(spawner: Spawner) -> ! { let mut config = Config::default(); config.rcc.sys_ck = Some(mhz(400)); config.rcc.hclk = Some(mhz(200)); config.rcc.pll1.q_ck = Some(mhz(100)); - config -} - -#[embassy_executor::main] -async fn main(spawner: Spawner) -> ! { - let p = embassy_stm32::init(config()); + let p = embassy_stm32::init(config); info!("Hello World!"); // Generate random seed. diff --git a/examples/stm32h7/src/bin/fmc.rs b/examples/stm32h7/src/bin/fmc.rs index 838427b0a..1a0d073d0 100644 --- a/examples/stm32h7/src/bin/fmc.rs +++ b/examples/stm32h7/src/bin/fmc.rs @@ -10,17 +10,14 @@ use embassy_stm32::time::mhz; use embassy_stm32::Config; use {defmt_rtt as _, panic_probe as _}; -pub fn config() -> Config { +#[embassy_executor::main] +async fn main(_spawner: Spawner) { let mut config = Config::default(); config.rcc.sys_ck = Some(mhz(400)); config.rcc.hclk = Some(mhz(200)); config.rcc.pll1.q_ck = Some(mhz(100)); - config -} + let p = embassy_stm32::init(config); -#[embassy_executor::main] -async fn main(_spawner: Spawner) { - let p = embassy_stm32::init(config()); info!("Hello World!"); let mut core_peri = cortex_m::Peripherals::take().unwrap(); diff --git a/examples/stm32h7/src/bin/low_level_timer_api.rs b/examples/stm32h7/src/bin/low_level_timer_api.rs index e759c47a8..59648d4b4 100644 --- a/examples/stm32h7/src/bin/low_level_timer_api.rs +++ b/examples/stm32h7/src/bin/low_level_timer_api.rs @@ -12,7 +12,8 @@ use embassy_stm32::time::{khz, mhz, Hertz}; use embassy_stm32::{into_ref, Config, Peripheral, PeripheralRef}; use {defmt_rtt as _, panic_probe as _}; -pub fn config() -> Config { +#[embassy_executor::main] +async fn main(_spawner: Spawner) { let mut config = Config::default(); config.rcc.sys_ck = Some(mhz(400)); config.rcc.hclk = Some(mhz(400)); @@ -21,12 +22,8 @@ pub fn config() -> Config { config.rcc.pclk2 = Some(mhz(100)); config.rcc.pclk3 = Some(mhz(100)); config.rcc.pclk4 = Some(mhz(100)); - config -} + let p = embassy_stm32::init(config); -#[embassy_executor::main] -async fn main(_spawner: Spawner) { - let p = embassy_stm32::init(config()); info!("Hello World!"); let mut pwm = SimplePwm32::new(p.TIM5, p.PA0, p.PA1, p.PA2, p.PA3, khz(10)); diff --git a/examples/stm32h7/src/bin/pwm.rs b/examples/stm32h7/src/bin/pwm.rs index 4797de0a0..b225d66e3 100644 --- a/examples/stm32h7/src/bin/pwm.rs +++ b/examples/stm32h7/src/bin/pwm.rs @@ -11,7 +11,8 @@ use embassy_stm32::time::{khz, mhz}; use embassy_stm32::Config; use {defmt_rtt as _, panic_probe as _}; -pub fn config() -> Config { +#[embassy_executor::main] +async fn main(_spawner: Spawner) { let mut config = Config::default(); config.rcc.sys_ck = Some(mhz(400)); config.rcc.hclk = Some(mhz(400)); @@ -20,12 +21,7 @@ pub fn config() -> Config { config.rcc.pclk2 = Some(mhz(100)); config.rcc.pclk3 = Some(mhz(100)); config.rcc.pclk4 = Some(mhz(100)); - config -} - -#[embassy_executor::main] -async fn main(_spawner: Spawner) { - let p = embassy_stm32::init(config()); + let p = embassy_stm32::init(config); info!("Hello World!"); let ch1 = PwmPin::new_ch1(p.PA6); diff --git a/examples/stm32h7/src/bin/sdmmc.rs b/examples/stm32h7/src/bin/sdmmc.rs index ec98bf14e..f44d88aca 100644 --- a/examples/stm32h7/src/bin/sdmmc.rs +++ b/examples/stm32h7/src/bin/sdmmc.rs @@ -9,15 +9,11 @@ use embassy_stm32::time::mhz; use embassy_stm32::{interrupt, Config}; use {defmt_rtt as _, panic_probe as _}; -fn config() -> Config { - let mut config = Config::default(); - config.rcc.sys_ck = Some(mhz(200)); - config -} - #[embassy_executor::main] async fn main(_spawner: Spawner) -> ! { - let p = embassy_stm32::init(config()); + let mut config = Config::default(); + config.rcc.sys_ck = Some(mhz(200)); + let p = embassy_stm32::init(config); info!("Hello World!"); let irq = interrupt::take!(SDMMC1); diff --git a/examples/stm32h7/src/bin/spi.rs b/examples/stm32h7/src/bin/spi.rs index dc8cb7f47..8f6f14850 100644 --- a/examples/stm32h7/src/bin/spi.rs +++ b/examples/stm32h7/src/bin/spi.rs @@ -16,14 +16,6 @@ use embassy_util::Forever; use heapless::String; use {defmt_rtt as _, panic_probe as _}; -pub fn config() -> Config { - let mut config = Config::default(); - config.rcc.sys_ck = Some(mhz(400)); - config.rcc.hclk = Some(mhz(200)); - config.rcc.pll1.q_ck = Some(mhz(100)); - config -} - #[embassy_executor::task] async fn main_task(mut spi: spi::Spi<'static, SPI3, NoDma, NoDma>) { for n in 0u32.. { @@ -45,7 +37,11 @@ static EXECUTOR: Forever = Forever::new(); fn main() -> ! { info!("Hello World!"); - let p = embassy_stm32::init(config()); + let mut config = Config::default(); + config.rcc.sys_ck = Some(mhz(400)); + config.rcc.hclk = Some(mhz(200)); + config.rcc.pll1.q_ck = Some(mhz(100)); + let p = embassy_stm32::init(config); let spi = spi::Spi::new( p.SPI3, diff --git a/examples/stm32h7/src/bin/spi_dma.rs b/examples/stm32h7/src/bin/spi_dma.rs index 2631ed30c..d4c91a8e3 100644 --- a/examples/stm32h7/src/bin/spi_dma.rs +++ b/examples/stm32h7/src/bin/spi_dma.rs @@ -15,14 +15,6 @@ use embassy_util::Forever; use heapless::String; use {defmt_rtt as _, panic_probe as _}; -pub fn config() -> Config { - let mut config = Config::default(); - config.rcc.sys_ck = Some(mhz(400)); - config.rcc.hclk = Some(mhz(200)); - config.rcc.pll1.q_ck = Some(mhz(100)); - config -} - #[embassy_executor::task] async fn main_task(mut spi: spi::Spi<'static, SPI3, DMA1_CH3, DMA1_CH4>) { for n in 0u32.. { @@ -41,7 +33,11 @@ static EXECUTOR: Forever = Forever::new(); fn main() -> ! { info!("Hello World!"); - let p = embassy_stm32::init(config()); + let mut config = Config::default(); + config.rcc.sys_ck = Some(mhz(400)); + config.rcc.hclk = Some(mhz(200)); + config.rcc.pll1.q_ck = Some(mhz(100)); + let p = embassy_stm32::init(config); let spi = spi::Spi::new( p.SPI3, diff --git a/examples/stm32l0/src/bin/button_exti.rs b/examples/stm32l0/src/bin/button_exti.rs index ab23fd5bc..bdd2fa3c1 100644 --- a/examples/stm32l0/src/bin/button_exti.rs +++ b/examples/stm32l0/src/bin/button_exti.rs @@ -6,17 +6,15 @@ use defmt::*; use embassy_executor::executor::Spawner; use embassy_stm32::exti::ExtiInput; use embassy_stm32::gpio::{Input, Pull}; +use embassy_stm32::Config; use {defmt_rtt as _, panic_probe as _}; -fn config() -> embassy_stm32::Config { - let mut config = embassy_stm32::Config::default(); - config.rcc.enable_hsi48 = true; - config -} - #[embassy_executor::main] async fn main(_spawner: Spawner) { - let p = embassy_stm32::init(config()); + let mut config = Config::default(); + config.rcc.enable_hsi48 = true; + let p = embassy_stm32::init(config); + let button = Input::new(p.PB2, Pull::Up); let mut button = ExtiInput::new(button, p.EXTI2); diff --git a/examples/stm32l0/src/bin/lorawan.rs b/examples/stm32l0/src/bin/lorawan.rs index 4e5b69362..9497cad72 100644 --- a/examples/stm32l0/src/bin/lorawan.rs +++ b/examples/stm32l0/src/bin/lorawan.rs @@ -18,16 +18,13 @@ use lorawan::default_crypto::DefaultFactory as Crypto; use lorawan_device::async_device::{region, Device, JoinMode}; use {defmt_rtt as _, panic_probe as _}; -fn config() -> embassy_stm32::Config { +#[embassy_executor::main] +async fn main(_spawner: Spawner) { let mut config = embassy_stm32::Config::default(); config.rcc.mux = embassy_stm32::rcc::ClockSrc::HSI16; config.rcc.enable_hsi48 = true; - config -} + let p = embassy_stm32::init(config); -#[embassy_executor::main] -async fn main(_spawner: Spawner) { - let p = embassy_stm32::init(config()); // SPI for sx127x let spi = spi::Spi::new( p.SPI1, diff --git a/examples/stm32l4/src/bin/rng.rs b/examples/stm32l4/src/bin/rng.rs index d0e1306a3..c90515626 100644 --- a/examples/stm32l4/src/bin/rng.rs +++ b/examples/stm32l4/src/bin/rng.rs @@ -9,7 +9,8 @@ use embassy_stm32::rng::Rng; use embassy_stm32::Config; use {defmt_rtt as _, panic_probe as _}; -fn config() -> Config { +#[embassy_executor::main] +async fn main(_spawner: Spawner) { let mut config = Config::default(); // 72Mhz clock (16 / 1 * 18 / 4) config.rcc.mux = ClockSrc::PLL( @@ -19,12 +20,8 @@ fn config() -> Config { PLLMul::Mul18, Some(PLLClkDiv::Div6), // 48Mhz (16 / 1 * 18 / 6) ); - config -} + let p = embassy_stm32::init(config); -#[embassy_executor::main] -async fn main(_spawner: Spawner) { - let p = embassy_stm32::init(config()); info!("Hello World!"); let mut rng = Rng::new(p.RNG); diff --git a/examples/stm32l5/src/bin/rng.rs b/examples/stm32l5/src/bin/rng.rs index b7919424a..cec9078e6 100644 --- a/examples/stm32l5/src/bin/rng.rs +++ b/examples/stm32l5/src/bin/rng.rs @@ -9,7 +9,8 @@ use embassy_stm32::rng::Rng; use embassy_stm32::Config; use {defmt_rtt as _, panic_probe as _}; -fn config() -> Config { +#[embassy_executor::main] +async fn main(_spawner: Spawner) { let mut config = Config::default(); config.rcc.mux = ClockSrc::PLL( PLLSource::HSI16, @@ -18,12 +19,8 @@ fn config() -> Config { PLLMul::Mul8, Some(PLLClkDiv::Div2), ); - config -} + let p = embassy_stm32::init(config); -#[embassy_executor::main] -async fn main(_spawner: Spawner) { - let p = embassy_stm32::init(config()); info!("Hello World!"); let mut rng = Rng::new(p.RNG); diff --git a/examples/stm32l5/src/bin/usb_ethernet.rs b/examples/stm32l5/src/bin/usb_ethernet.rs index cc7578990..769b67a2b 100644 --- a/examples/stm32l5/src/bin/usb_ethernet.rs +++ b/examples/stm32l5/src/bin/usb_ethernet.rs @@ -83,19 +83,13 @@ async fn net_task(stack: &'static Stack) -> ! { stack.run().await } -fn config() -> Config { - let mut config = Config::default(); - config.rcc.mux = ClockSrc::HSE(Hertz(16_000_000)); - - config.rcc.mux = ClockSrc::PLL(PLLSource::HSI16, PLLClkDiv::Div2, PLLSrcDiv::Div1, PLLMul::Mul10, None); - config.rcc.hsi48 = true; - - config -} - #[embassy_executor::main] async fn main(spawner: Spawner) { - let p = embassy_stm32::init(config()); + let mut config = Config::default(); + config.rcc.mux = ClockSrc::PLL(PLLSource::HSI16, PLLClkDiv::Div2, PLLSrcDiv::Div1, PLLMul::Mul10, None); + config.rcc.hsi48 = true; + let p = embassy_stm32::init(config); + // Create the driver, from the HAL. let irq = interrupt::take!(USB_FS); let driver = Driver::new(p.USB, irq, p.PA12, p.PA11); diff --git a/examples/stm32l5/src/bin/usb_hid_mouse.rs b/examples/stm32l5/src/bin/usb_hid_mouse.rs index b8eef6d0d..ef0a20a42 100644 --- a/examples/stm32l5/src/bin/usb_hid_mouse.rs +++ b/examples/stm32l5/src/bin/usb_hid_mouse.rs @@ -17,19 +17,13 @@ use futures::future::join; use usbd_hid::descriptor::{MouseReport, SerializedDescriptor}; use {defmt_rtt as _, panic_probe as _}; -fn config() -> Config { - let mut config = Config::default(); - config.rcc.mux = ClockSrc::HSE(Hertz(16_000_000)); - - config.rcc.mux = ClockSrc::PLL(PLLSource::HSI16, PLLClkDiv::Div2, PLLSrcDiv::Div1, PLLMul::Mul10, None); - config.rcc.hsi48 = true; - - config -} - #[embassy_executor::main] async fn main(_spawner: Spawner) { - let p = embassy_stm32::init(config()); + let mut config = Config::default(); + config.rcc.mux = ClockSrc::PLL(PLLSource::HSI16, PLLClkDiv::Div2, PLLSrcDiv::Div1, PLLMul::Mul10, None); + config.rcc.hsi48 = true; + let p = embassy_stm32::init(config); + // Create the driver, from the HAL. let irq = interrupt::take!(USB_FS); let driver = Driver::new(p.USB, irq, p.PA12, p.PA11); diff --git a/examples/stm32l5/src/bin/usb_serial.rs b/examples/stm32l5/src/bin/usb_serial.rs index f8894231c..a763a0b56 100644 --- a/examples/stm32l5/src/bin/usb_serial.rs +++ b/examples/stm32l5/src/bin/usb_serial.rs @@ -14,19 +14,13 @@ use embassy_usb_serial::{CdcAcmClass, State}; use futures::future::join; use {defmt_rtt as _, panic_probe as _}; -fn config() -> Config { - let mut config = Config::default(); - config.rcc.mux = ClockSrc::HSE(Hertz(16_000_000)); - - config.rcc.mux = ClockSrc::PLL(PLLSource::HSI16, PLLClkDiv::Div2, PLLSrcDiv::Div1, PLLMul::Mul10, None); - config.rcc.hsi48 = true; - - config -} - #[embassy_executor::main] async fn main(_spawner: Spawner) { - let p = embassy_stm32::init(config()); + let mut config = Config::default(); + config.rcc.mux = ClockSrc::PLL(PLLSource::HSI16, PLLClkDiv::Div2, PLLSrcDiv::Div1, PLLMul::Mul10, None); + config.rcc.hsi48 = true; + let p = embassy_stm32::init(config); + info!("Hello World!"); // Create the driver, from the HAL. diff --git a/examples/stm32wl/src/bin/lorawan.rs b/examples/stm32wl/src/bin/lorawan.rs index 35dae71a6..b6a3ca905 100644 --- a/examples/stm32wl/src/bin/lorawan.rs +++ b/examples/stm32wl/src/bin/lorawan.rs @@ -17,16 +17,13 @@ use lorawan::default_crypto::DefaultFactory as Crypto; use lorawan_device::async_device::{region, Device, JoinMode}; use {defmt_rtt as _, panic_probe as _}; -fn config() -> embassy_stm32::Config { +#[embassy_executor::main] +async fn main(_spawner: Spawner) { let mut config = embassy_stm32::Config::default(); config.rcc.mux = embassy_stm32::rcc::ClockSrc::HSI16; config.rcc.enable_lsi = true; - config -} + let p = embassy_stm32::init(config); -#[embassy_executor::main] -async fn main(_spawner: Spawner) { - let p = embassy_stm32::init(config()); unsafe { pac::RCC.ccipr().modify(|w| w.set_rngsel(0b01)) } let ctrl1 = Output::new(p.PC3.degrade(), Level::High, Speed::High); diff --git a/examples/stm32wl/src/bin/subghz.rs b/examples/stm32wl/src/bin/subghz.rs index 0e2d4103f..1b096514b 100644 --- a/examples/stm32wl/src/bin/subghz.rs +++ b/examples/stm32wl/src/bin/subghz.rs @@ -52,15 +52,12 @@ const TCXO_MODE: TcxoMode = TcxoMode::new() const TX_PARAMS: TxParams = TxParams::new().set_power(0x0D).set_ramp_time(RampTime::Micros40); -fn config() -> embassy_stm32::Config { - let mut config = embassy_stm32::Config::default(); - config.rcc.mux = embassy_stm32::rcc::ClockSrc::HSE32; - config -} - #[embassy_executor::main] async fn main(_spawner: Spawner) { - let p = embassy_stm32::init(config()); + let mut config = embassy_stm32::Config::default(); + config.rcc.mux = embassy_stm32::rcc::ClockSrc::HSE32; + let p = embassy_stm32::init(config); + let mut led1 = Output::new(p.PB15, Level::High, Speed::Low); let mut led2 = Output::new(p.PB9, Level::Low, Speed::Low); let mut led3 = Output::new(p.PB11, Level::Low, Speed::Low);