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.
This commit is contained in:
Dario Nieuwenhuis 2022-08-17 22:25:58 +02:00
parent fc6e1e06b3
commit 2e85eaf7d5
30 changed files with 121 additions and 229 deletions

View File

@ -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;

View File

@ -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!");
{

View File

@ -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");

View File

@ -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;

View File

@ -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

View File

@ -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;

View File

@ -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);

View File

@ -33,15 +33,12 @@ async fn net_task(stack: &'static Stack<Device>) -> ! {
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.

View File

@ -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;

View File

@ -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);

View File

@ -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);

View File

@ -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));

View File

@ -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);

View File

@ -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.

View File

@ -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.

View File

@ -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();

View File

@ -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));

View File

@ -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);

View File

@ -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);

View File

@ -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,

View File

@ -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,

View File

@ -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);

View File

@ -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,

View File

@ -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);

View File

@ -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);

View File

@ -83,19 +83,13 @@ async fn net_task(stack: &'static Stack<Device>) -> ! {
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);

View File

@ -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);

View File

@ -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.

View File

@ -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);

View File

@ -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);