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]
|
#[non_exhaustive]
|
||||||
pub struct Config {
|
pub struct Config {
|
||||||
rcc: rcc::Config,
|
pub rcc: rcc::Config,
|
||||||
}
|
|
||||||
|
|
||||||
impl Config {
|
|
||||||
pub fn rcc(mut self, rcc: rcc::Config) -> Self {
|
|
||||||
self.rcc = rcc;
|
|
||||||
self
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for Config {
|
impl Default for Config {
|
||||||
|
@ -68,83 +68,7 @@ pub struct Config {
|
|||||||
pub pll1: PllConfig,
|
pub pll1: PllConfig,
|
||||||
pub pll2: PllConfig,
|
pub pll2: PllConfig,
|
||||||
pub pll3: PllConfig,
|
pub pll3: PllConfig,
|
||||||
}
|
pub enable_dma1: bool,
|
||||||
|
|
||||||
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 struct Rcc<'d> {
|
pub struct Rcc<'d> {
|
||||||
@ -402,6 +326,10 @@ impl<'d> Rcc<'d> {
|
|||||||
});
|
});
|
||||||
while !SYSCFG.cccsr().read().ready() {}
|
while !SYSCFG.cccsr().read().ready() {}
|
||||||
|
|
||||||
|
if self.config.enable_dma1 {
|
||||||
|
RCC.ahb1enr().modify(|w| w.set_dma1en(true));
|
||||||
|
}
|
||||||
|
|
||||||
CoreClocks {
|
CoreClocks {
|
||||||
hclk: Hertz(rcc_hclk),
|
hclk: Hertz(rcc_hclk),
|
||||||
pclk1: Hertz(rcc_pclk1),
|
pclk1: Hertz(rcc_pclk1),
|
||||||
|
@ -6,13 +6,12 @@ use panic_probe as _;
|
|||||||
pub use defmt::*;
|
pub use defmt::*;
|
||||||
|
|
||||||
use core::sync::atomic::{AtomicUsize, Ordering};
|
use core::sync::atomic::{AtomicUsize, Ordering};
|
||||||
use embassy_stm32::rcc;
|
|
||||||
use embassy_stm32::Config;
|
use embassy_stm32::Config;
|
||||||
|
|
||||||
pub fn config() -> Config {
|
pub fn config() -> Config {
|
||||||
let mut rcc_config = rcc::Config::default();
|
let mut config = Config::default();
|
||||||
rcc_config.enable_debug_wfe = true;
|
config.rcc.enable_debug_wfe = true;
|
||||||
Config::default().rcc(rcc_config)
|
config
|
||||||
}
|
}
|
||||||
|
|
||||||
defmt::timestamp! {"{=u64}", {
|
defmt::timestamp! {"{=u64}", {
|
||||||
|
@ -7,7 +7,6 @@
|
|||||||
use defmt::{info, panic};
|
use defmt::{info, panic};
|
||||||
use embassy::executor::Spawner;
|
use embassy::executor::Spawner;
|
||||||
use embassy::time::{Duration, Timer};
|
use embassy::time::{Duration, Timer};
|
||||||
use embassy_stm32::rcc::Config as RccConfig;
|
|
||||||
use embassy_stm32::time::Hertz;
|
use embassy_stm32::time::Hertz;
|
||||||
use embassy_stm32::Config;
|
use embassy_stm32::Config;
|
||||||
use embassy_stm32::Peripherals;
|
use embassy_stm32::Peripherals;
|
||||||
@ -16,11 +15,10 @@ use embassy_stm32::Peripherals;
|
|||||||
mod example_common;
|
mod example_common;
|
||||||
|
|
||||||
fn config() -> Config {
|
fn config() -> Config {
|
||||||
let mut rcc_config = RccConfig::default();
|
let mut config = Config::default();
|
||||||
rcc_config.sys_ck = Some(Hertz(84_000_000));
|
config.rcc.sys_ck = Some(Hertz(84_000_000));
|
||||||
rcc_config.enable_debug_wfe = true;
|
config.rcc.enable_debug_wfe = true;
|
||||||
|
config
|
||||||
Config::default().rcc(rcc_config)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[embassy::main(config = "config()")]
|
#[embassy::main(config = "config()")]
|
||||||
|
@ -12,17 +12,12 @@ use example_common::*;
|
|||||||
|
|
||||||
use cortex_m_rt::entry;
|
use cortex_m_rt::entry;
|
||||||
use embassy_stm32::dac::{Channel, Dac, Value};
|
use embassy_stm32::dac::{Channel, Dac, Value};
|
||||||
use embassy_stm32::rcc;
|
|
||||||
use embassy_stm32::time::U32Ext;
|
|
||||||
use embassy_stm32::Config;
|
|
||||||
|
|
||||||
#[entry]
|
#[entry]
|
||||||
fn main() -> ! {
|
fn main() -> ! {
|
||||||
info!("Hello World, dude!");
|
info!("Hello World, dude!");
|
||||||
|
|
||||||
let p = embassy_stm32::init(
|
let p = embassy_stm32::init(config());
|
||||||
Config::default().rcc(rcc::Config::default().sys_ck(400.mhz()).pll1_q(100.mhz())),
|
|
||||||
);
|
|
||||||
|
|
||||||
unsafe {
|
unsafe {
|
||||||
Dbgmcu::enable_all();
|
Dbgmcu::enable_all();
|
||||||
|
@ -4,7 +4,9 @@
|
|||||||
#![feature(trait_alias)]
|
#![feature(trait_alias)]
|
||||||
#![feature(type_alias_impl_trait)]
|
#![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 cortex_m_rt::entry;
|
||||||
use defmt::{info, unwrap};
|
use defmt::{info, unwrap};
|
||||||
@ -18,25 +20,15 @@ use embassy_net::{
|
|||||||
Config as NetConfig, Ipv4Address, Ipv4Cidr, StackResources, StaticConfigurator, TcpSocket,
|
Config as NetConfig, Ipv4Address, Ipv4Cidr, StackResources, StaticConfigurator, TcpSocket,
|
||||||
};
|
};
|
||||||
use embassy_stm32::clock::{Alarm, Clock};
|
use embassy_stm32::clock::{Alarm, Clock};
|
||||||
|
use embassy_stm32::dbgmcu::Dbgmcu;
|
||||||
use embassy_stm32::eth::lan8742a::LAN8742A;
|
use embassy_stm32::eth::lan8742a::LAN8742A;
|
||||||
use embassy_stm32::eth::{Ethernet, State};
|
use embassy_stm32::eth::{Ethernet, State};
|
||||||
use embassy_stm32::rcc::{Config as RccConfig, Rcc};
|
|
||||||
use embassy_stm32::rng::Random;
|
use embassy_stm32::rng::Random;
|
||||||
use embassy_stm32::time::Hertz;
|
use embassy_stm32::{interrupt, peripherals};
|
||||||
use embassy_stm32::{interrupt, peripherals, Config};
|
|
||||||
use heapless::Vec;
|
use heapless::Vec;
|
||||||
use panic_probe as _;
|
use panic_probe as _;
|
||||||
use peripherals::{RNG, TIM2};
|
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]
|
#[embassy::task]
|
||||||
async fn main_task(
|
async fn main_task(
|
||||||
device: &'static mut Ethernet<'static, LAN8742A, 4, 4>,
|
device: &'static mut Ethernet<'static, LAN8742A, 4, 4>,
|
||||||
@ -106,17 +98,12 @@ fn main() -> ! {
|
|||||||
info!("Hello World!");
|
info!("Hello World!");
|
||||||
|
|
||||||
info!("Setup RCC...");
|
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 p = embassy_stm32::init(config());
|
||||||
|
|
||||||
let mut rcc = Rcc::new(&mut p.RCC, RccConfig::default());
|
|
||||||
rcc.enable_debug_wfe(&mut p.DBGMCU, true);
|
|
||||||
|
|
||||||
let rtc_int = interrupt_take!(TIM2);
|
let rtc_int = interrupt_take!(TIM2);
|
||||||
let rtc = TIMER_RTC.put(Clock::new(p.TIM2, rtc_int));
|
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::time::Clock;
|
||||||
use embassy::util::Forever;
|
use embassy::util::Forever;
|
||||||
use embassy_stm32::dma::NoDma;
|
use embassy_stm32::dma::NoDma;
|
||||||
use embassy_stm32::rcc;
|
|
||||||
use embassy_stm32::spi;
|
use embassy_stm32::spi;
|
||||||
use embassy_stm32::Config;
|
|
||||||
use embedded_hal::blocking::spi::Transfer;
|
use embedded_hal::blocking::spi::Transfer;
|
||||||
use example_common::*;
|
use example_common::*;
|
||||||
|
|
||||||
@ -58,9 +56,7 @@ fn main() -> ! {
|
|||||||
Dbgmcu::enable_all();
|
Dbgmcu::enable_all();
|
||||||
}
|
}
|
||||||
|
|
||||||
let p = embassy_stm32::init(
|
let p = embassy_stm32::init(config());
|
||||||
Config::default().rcc(rcc::Config::default().sys_ck(400.mhz()).pll1_q(100.mhz())),
|
|
||||||
);
|
|
||||||
|
|
||||||
let spi = spi::Spi::new(
|
let spi = spi::Spi::new(
|
||||||
p.SPI3,
|
p.SPI3,
|
||||||
|
@ -6,6 +6,7 @@
|
|||||||
|
|
||||||
#[path = "../example_common.rs"]
|
#[path = "../example_common.rs"]
|
||||||
mod example_common;
|
mod example_common;
|
||||||
|
|
||||||
use core::fmt::Write;
|
use core::fmt::Write;
|
||||||
use embassy::executor::Executor;
|
use embassy::executor::Executor;
|
||||||
use embassy::time::Clock;
|
use embassy::time::Clock;
|
||||||
@ -18,9 +19,7 @@ use core::str::from_utf8;
|
|||||||
use cortex_m_rt::entry;
|
use cortex_m_rt::entry;
|
||||||
use embassy_stm32::dbgmcu::Dbgmcu;
|
use embassy_stm32::dbgmcu::Dbgmcu;
|
||||||
use embassy_stm32::peripherals::{DMA1_CH3, DMA1_CH4, SPI3};
|
use embassy_stm32::peripherals::{DMA1_CH3, DMA1_CH4, SPI3};
|
||||||
use embassy_stm32::rcc;
|
|
||||||
use embassy_stm32::spi;
|
use embassy_stm32::spi;
|
||||||
use embassy_stm32::Config;
|
|
||||||
use heapless::String;
|
use heapless::String;
|
||||||
|
|
||||||
#[embassy::task]
|
#[embassy::task]
|
||||||
@ -53,9 +52,7 @@ fn main() -> ! {
|
|||||||
Dbgmcu::enable_all();
|
Dbgmcu::enable_all();
|
||||||
}
|
}
|
||||||
|
|
||||||
let p = embassy_stm32::init(
|
let p = embassy_stm32::init(config());
|
||||||
Config::default().rcc(rcc::Config::default().sys_ck(400.mhz()).pll1_q(100.mhz())),
|
|
||||||
);
|
|
||||||
|
|
||||||
let spi = spi::Spi::new(
|
let spi = spi::Spi::new(
|
||||||
p.SPI3,
|
p.SPI3,
|
||||||
|
@ -6,6 +6,8 @@ use panic_probe as _;
|
|||||||
pub use defmt::*;
|
pub use defmt::*;
|
||||||
|
|
||||||
use core::sync::atomic::{AtomicUsize, Ordering};
|
use core::sync::atomic::{AtomicUsize, Ordering};
|
||||||
|
use embassy_stm32::time::U32Ext;
|
||||||
|
use embassy_stm32::Config;
|
||||||
|
|
||||||
defmt::timestamp! {"{=u64}", {
|
defmt::timestamp! {"{=u64}", {
|
||||||
static COUNT: AtomicUsize = AtomicUsize::new(0);
|
static COUNT: AtomicUsize = AtomicUsize::new(0);
|
||||||
@ -15,3 +17,12 @@ defmt::timestamp! {"{=u64}", {
|
|||||||
n as 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