diff options
30 files changed, 107 insertions, 215 deletions
diff --git a/examples/stm32f1/src/bin/hello.rs b/examples/stm32f1/src/bin/hello.rs index 721b21c3..57892d3c 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 { +#[embassy_executor::main] +async fn main(_spawner: Spawner) -> ! { let mut config = Config::default(); config.rcc.sys_ck = Some(Hertz(36_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/stm32f1/src/bin/usb_serial.rs b/examples/stm32f1/src/bin/usb_serial.rs index 7f27e625..2301c51b 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 bc0c160b..6fce7a71 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 7846912c..cd59f740 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 36d38d87..757643ea 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 6facb9bb..26d3555a 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 { +#[embassy_executor::main] +async fn main(_spawner: Spawner) -> ! { let mut config = Config::default(); config.rcc.sys_ck = Some(Hertz(84_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/stm32f4/src/bin/sdmmc.rs b/examples/stm32f4/src/bin/sdmmc.rs index 996694f2..b8e56d2e 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 f8904fa0..1ec30353 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<Device>) -> ! { stack.run().await } -fn config() -> Config { +#[embassy_executor::main] +async fn main(spawner: Spawner) -> ! { let mut config = Config::default(); config.rcc.sys_ck = Some(mhz(200)); - config -} + let p = embassy_stm32::init(config); -#[embassy_executor::main] -async fn main(spawner: Spawner) -> ! { - 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 6facb9bb..26d3555a 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 { +#[embassy_executor::main] +async fn main(_spawner: Spawner) -> ! { let mut config = Config::default(); config.rcc.sys_ck = Some(Hertz(84_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/stm32f7/src/bin/sdmmc.rs b/examples/stm32f7/src/bin/sdmmc.rs index 975c5b91..9d97a1de 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 { +#[embassy_executor::main] +async fn main(_spawner: Spawner) -> ! { let mut config = Config::default(); config.rcc.sys_ck = Some(mhz(200)); - 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 irq = interrupt::take!(SDMMC1); diff --git a/examples/stm32h7/src/bin/adc.rs b/examples/stm32h7/src/bin/adc.rs index 96457e76..0715a0f6 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 8e93a54c..a281e75c 100644 --- a/examples/stm32h7/src/bin/camera.rs +++ b/examples/stm32h7/src/bin/camera.rs @@ -10,10 +10,16 @@ use embassy_stm32::i2c::I2c; use embassy_stm32::rcc::{Mco, Mco1Source, McoClock}; use embassy_stm32::time::{khz, mhz}; use embassy_stm32::{interrupt, Config}; +use ov7725::*; use {defmt_rtt as _, panic_probe as _}; -#[allow(unused)] -pub fn config() -> Config { +const WIDTH: usize = 100; +const HEIGHT: usize = 100; + +static mut FRAME: [u32; WIDTH * HEIGHT / 2] = [0u32; WIDTH * HEIGHT / 2]; + +#[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)); @@ -22,19 +28,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); -use ov7725::*; - -const WIDTH: usize = 100; -const HEIGHT: usize = 100; - -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()); 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 dece74bb..f1271637 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 7ad2f52c..9039b7ee 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<Device>) -> ! { 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 736a2992..25e75d71 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<Device>) -> ! { 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 838427b0..1a0d073d 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 e759c47a..59648d4b 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 4797de0a..b225d66e 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 ec98bf14..f44d88ac 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 dc8cb7f4..8f6f1485 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<Executor> = 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 2631ed30..d4c91a8e 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<Executor> = 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 ab23fd5b..bdd2fa3c 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 4e5b6936..9497cad7 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 d0e1306a..c9051562 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 b7919424..cec9078e 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 cc757899..769b67a2 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<Device>) -> ! { stack.run().await } -fn config() -> Config { +#[embassy_executor::main] +async fn main(spawner: Spawner) { 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; + let p = embassy_stm32::init(config); - config -} - -#[embassy_executor::main] -async fn main(spawner: Spawner) { - 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 b8eef6d0..ef0a20a4 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 { +#[embassy_executor::main] +async fn main(_spawner: Spawner) { 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; + let p = embassy_stm32::init(config); - config -} - -#[embassy_executor::main] -async fn main(_spawner: Spawner) { - 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 f8894231..a763a0b5 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 { +#[embassy_executor::main] +async fn main(_spawner: Spawner) { 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; + let p = embassy_stm32::init(config); - config -} - -#[embassy_executor::main] -async fn main(_spawner: Spawner) { - 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 35dae71a..b6a3ca90 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 0e2d4103..1b096514 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 { +#[embassy_executor::main] +async fn main(_spawner: Spawner) { let mut config = embassy_stm32::Config::default(); config.rcc.mux = embassy_stm32::rcc::ClockSrc::HSE32; - config -} + let p = embassy_stm32::init(config); -#[embassy_executor::main] -async fn main(_spawner: Spawner) { - 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); |