Merge pull request #344 from bobmcwhirter/remove_builders
Remove builders from Config(s) and examples.
This commit is contained in:
commit
cfa1f61154
@ -65,14 +65,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 {
|
||||
|
@ -68,83 +68,7 @@ pub struct Config {
|
||||
pub pll1: PllConfig,
|
||||
pub pll2: PllConfig,
|
||||
pub pll3: PllConfig,
|
||||
}
|
||||
|
||||
impl Config {
|
||||
pub fn sys_ck<T: Into<Hertz>>(mut self, freq: T) -> Self {
|
||||
self.sys_ck = Some(freq.into());
|
||||
self
|
||||
}
|
||||
|
||||
pub fn per_ck<T: Into<Hertz>>(mut self, freq: T) -> Self {
|
||||
self.per_ck = Some(freq.into());
|
||||
self
|
||||
}
|
||||
|
||||
pub fn pclk1<T: Into<Hertz>>(mut self, freq: T) -> Self {
|
||||
self.pclk1 = Some(freq.into());
|
||||
self
|
||||
}
|
||||
|
||||
pub fn pclk2<T: Into<Hertz>>(mut self, freq: T) -> Self {
|
||||
self.pclk2 = Some(freq.into());
|
||||
self
|
||||
}
|
||||
|
||||
pub fn pclk3<T: Into<Hertz>>(mut self, freq: T) -> Self {
|
||||
self.pclk3 = Some(freq.into());
|
||||
self
|
||||
}
|
||||
|
||||
pub fn pclk4<T: Into<Hertz>>(mut self, freq: T) -> Self {
|
||||
self.pclk4 = Some(freq.into());
|
||||
self
|
||||
}
|
||||
|
||||
pub fn pll1_p<T: Into<Hertz>>(mut self, freq: T) -> Self {
|
||||
self.pll1.p_ck = Some(freq.into());
|
||||
self
|
||||
}
|
||||
|
||||
pub fn pll1_q<T: Into<Hertz>>(mut self, freq: T) -> Self {
|
||||
self.pll1.q_ck = Some(freq.into());
|
||||
self
|
||||
}
|
||||
|
||||
pub fn pll1_r<T: Into<Hertz>>(mut self, freq: T) -> Self {
|
||||
self.pll1.r_ck = Some(freq.into());
|
||||
self
|
||||
}
|
||||
|
||||
pub fn pll2_p<T: Into<Hertz>>(mut self, freq: T) -> Self {
|
||||
self.pll2.p_ck = Some(freq.into());
|
||||
self
|
||||
}
|
||||
|
||||
pub fn pll2_q<T: Into<Hertz>>(mut self, freq: T) -> Self {
|
||||
self.pll2.q_ck = Some(freq.into());
|
||||
self
|
||||
}
|
||||
|
||||
pub fn pll2_r<T: Into<Hertz>>(mut self, freq: T) -> Self {
|
||||
self.pll2.r_ck = Some(freq.into());
|
||||
self
|
||||
}
|
||||
|
||||
pub fn pll3_p<T: Into<Hertz>>(mut self, freq: T) -> Self {
|
||||
self.pll3.p_ck = Some(freq.into());
|
||||
self
|
||||
}
|
||||
|
||||
pub fn pll3_q<T: Into<Hertz>>(mut self, freq: T) -> Self {
|
||||
self.pll3.q_ck = Some(freq.into());
|
||||
self
|
||||
}
|
||||
|
||||
pub fn pll3_r<T: Into<Hertz>>(mut self, freq: T) -> Self {
|
||||
self.pll3.r_ck = Some(freq.into());
|
||||
self
|
||||
}
|
||||
pub enable_dma1: bool,
|
||||
}
|
||||
|
||||
pub struct Rcc<'d> {
|
||||
@ -402,6 +326,10 @@ impl<'d> Rcc<'d> {
|
||||
});
|
||||
while !SYSCFG.cccsr().read().ready() {}
|
||||
|
||||
if self.config.enable_dma1 {
|
||||
RCC.ahb1enr().modify(|w| w.set_dma1en(true));
|
||||
}
|
||||
|
||||
CoreClocks {
|
||||
hclk: Hertz(rcc_hclk),
|
||||
pclk1: Hertz(rcc_pclk1),
|
||||
|
@ -6,13 +6,12 @@ use panic_probe as _;
|
||||
pub use defmt::*;
|
||||
|
||||
use core::sync::atomic::{AtomicUsize, Ordering};
|
||||
use embassy_stm32::rcc;
|
||||
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.enable_debug_wfe = true;
|
||||
config
|
||||
}
|
||||
|
||||
defmt::timestamp! {"{=u64}", {
|
||||
|
@ -7,7 +7,6 @@
|
||||
use defmt::{info, panic};
|
||||
use embassy::executor::Spawner;
|
||||
use embassy::time::{Duration, Timer};
|
||||
use embassy_stm32::rcc::Config as RccConfig;
|
||||
use embassy_stm32::time::Hertz;
|
||||
use embassy_stm32::Config;
|
||||
use embassy_stm32::Peripherals;
|
||||
@ -16,11 +15,10 @@ use embassy_stm32::Peripherals;
|
||||
mod example_common;
|
||||
|
||||
fn config() -> Config {
|
||||
let mut rcc_config = RccConfig::default();
|
||||
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.sys_ck = Some(Hertz(84_000_000));
|
||||
config.rcc.enable_debug_wfe = true;
|
||||
config
|
||||
}
|
||||
|
||||
#[embassy::main(config = "config()")]
|
||||
|
@ -12,17 +12,12 @@ use example_common::*;
|
||||
|
||||
use cortex_m_rt::entry;
|
||||
use embassy_stm32::dac::{Channel, Dac, Value};
|
||||
use embassy_stm32::rcc;
|
||||
use embassy_stm32::time::U32Ext;
|
||||
use embassy_stm32::Config;
|
||||
|
||||
#[entry]
|
||||
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();
|
||||
|
@ -4,7 +4,9 @@
|
||||
#![feature(trait_alias)]
|
||||
#![feature(type_alias_impl_trait)]
|
||||
|
||||
use core::sync::atomic::{AtomicUsize, Ordering};
|
||||
#[path = "../example_common.rs"]
|
||||
mod example_common;
|
||||
use example_common::config;
|
||||
|
||||
use cortex_m_rt::entry;
|
||||
use defmt::{info, unwrap};
|
||||
@ -18,25 +20,15 @@ use embassy_net::{
|
||||
Config as NetConfig, Ipv4Address, Ipv4Cidr, StackResources, StaticConfigurator, TcpSocket,
|
||||
};
|
||||
use embassy_stm32::clock::{Alarm, Clock};
|
||||
use embassy_stm32::dbgmcu::Dbgmcu;
|
||||
use embassy_stm32::eth::lan8742a::LAN8742A;
|
||||
use embassy_stm32::eth::{Ethernet, State};
|
||||
use embassy_stm32::rcc::{Config as RccConfig, Rcc};
|
||||
use embassy_stm32::rng::Random;
|
||||
use embassy_stm32::time::Hertz;
|
||||
use embassy_stm32::{interrupt, peripherals, Config};
|
||||
use embassy_stm32::{interrupt, peripherals};
|
||||
use heapless::Vec;
|
||||
use panic_probe as _;
|
||||
use peripherals::{RNG, TIM2};
|
||||
|
||||
defmt::timestamp! {"{=u64}", {
|
||||
static COUNT: AtomicUsize = AtomicUsize::new(0);
|
||||
// NOTE(no-CAS) `timestamps` runs with interrupts disabled
|
||||
let n = COUNT.load(Ordering::Relaxed);
|
||||
COUNT.store(n + 1, Ordering::Relaxed);
|
||||
n as u64
|
||||
}
|
||||
}
|
||||
|
||||
#[embassy::task]
|
||||
async fn main_task(
|
||||
device: &'static mut Ethernet<'static, LAN8742A, 4, 4>,
|
||||
@ -106,17 +98,12 @@ 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);
|
||||
unsafe {
|
||||
Dbgmcu::enable_all();
|
||||
}
|
||||
|
||||
// Constrain and Freeze clock
|
||||
|
||||
let mut rcc = Rcc::new(&mut p.RCC, RccConfig::default());
|
||||
rcc.enable_debug_wfe(&mut p.DBGMCU, true);
|
||||
let p = embassy_stm32::init(config());
|
||||
|
||||
let rtc_int = interrupt_take!(TIM2);
|
||||
let rtc = TIMER_RTC.put(Clock::new(p.TIM2, rtc_int));
|
||||
|
@ -12,9 +12,7 @@ use embassy::executor::Executor;
|
||||
use embassy::time::Clock;
|
||||
use embassy::util::Forever;
|
||||
use embassy_stm32::dma::NoDma;
|
||||
use embassy_stm32::rcc;
|
||||
use embassy_stm32::spi;
|
||||
use embassy_stm32::Config;
|
||||
use embedded_hal::blocking::spi::Transfer;
|
||||
use example_common::*;
|
||||
|
||||
@ -58,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,
|
||||
|
@ -6,6 +6,7 @@
|
||||
|
||||
#[path = "../example_common.rs"]
|
||||
mod example_common;
|
||||
|
||||
use core::fmt::Write;
|
||||
use embassy::executor::Executor;
|
||||
use embassy::time::Clock;
|
||||
@ -18,9 +19,7 @@ use core::str::from_utf8;
|
||||
use cortex_m_rt::entry;
|
||||
use embassy_stm32::dbgmcu::Dbgmcu;
|
||||
use embassy_stm32::peripherals::{DMA1_CH3, DMA1_CH4, SPI3};
|
||||
use embassy_stm32::rcc;
|
||||
use embassy_stm32::spi;
|
||||
use embassy_stm32::Config;
|
||||
use heapless::String;
|
||||
|
||||
#[embassy::task]
|
||||
@ -53,9 +52,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,
|
||||
|
@ -6,6 +6,8 @@ use panic_probe as _;
|
||||
pub use defmt::*;
|
||||
|
||||
use core::sync::atomic::{AtomicUsize, Ordering};
|
||||
use embassy_stm32::time::U32Ext;
|
||||
use embassy_stm32::Config;
|
||||
|
||||
defmt::timestamp! {"{=u64}", {
|
||||
static COUNT: AtomicUsize = AtomicUsize::new(0);
|
||||
@ -15,3 +17,12 @@ defmt::timestamp! {"{=u64}", {
|
||||
n as u64
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(unused)]
|
||||
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
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user