Further work sharing config for example and removing duplicated code.

This commit is contained in:
Bob McWhirter 2021-08-04 13:39:02 -04:00
parent 4fe9114695
commit f4971fbb79
6 changed files with 25 additions and 73 deletions

View File

@ -68,6 +68,7 @@ pub struct Config {
pub pll1: PllConfig,
pub pll2: PllConfig,
pub pll3: PllConfig,
pub enable_dma1: bool,
}
pub struct Rcc<'d> {
@ -325,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),

View File

@ -14,9 +14,6 @@ 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() -> ! {
@ -52,16 +49,3 @@ fn to_sine_wave(v: u8) -> u8 {
(r.sin() * 128.0 + 127.0) as u8
}
}
fn config() -> Config {
let mut config = Config::default();
config.rcc = rcc_config();
config
}
fn rcc_config() -> rcc::Config {
let mut config = rcc::Config::default();
config.sys_ck = Some(400.mhz().into());
config.pll1.q_ck = Some(100.mhz().into());
config
}

View File

@ -6,7 +6,9 @@
#![feature(impl_trait_in_bindings)]
#![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};
@ -22,22 +24,12 @@ use embassy_net::{
use embassy_stm32::clock::{Alarm, Clock};
use embassy_stm32::eth::lan8742a::LAN8742A;
use embassy_stm32::eth::{Ethernet, State};
use embassy_stm32::rcc::{self, Rcc};
use embassy_stm32::rng::Random;
use embassy_stm32::time::U32Ext;
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
}
}
use embassy_stm32::dbgmcu::Dbgmcu;
#[embassy::task]
async fn main_task(
@ -108,12 +100,12 @@ fn main() -> ! {
info!("Hello World!");
info!("Setup RCC...");
let mut p = embassy_stm32::init(config());
// Constrain and Freeze clock
unsafe {
Dbgmcu::enable_all();
}
let mut rcc = Rcc::new(&mut p.RCC, rcc::Config::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));
@ -152,16 +144,3 @@ fn main() -> ! {
unwrap!(spawner.spawn(main_task(eth, config, spawner)));
})
}
fn config() -> Config {
let mut config = Config::default();
config.rcc = rcc_config();
config
}
fn rcc_config() -> rcc::Config {
let mut config = rcc::Config::default();
config.sys_ck = Some(400.mhz().into());
config.pll1.q_ck = Some(100.mhz().into());
config
}

View File

@ -14,9 +14,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::*;
@ -81,15 +79,3 @@ fn main() -> ! {
})
}
fn config() -> Config {
let mut config = Config::default();
config.rcc = rcc_config();
config
}
fn rcc_config() -> rcc::Config {
let mut config = rcc::Config::default();
config.sys_ck = Some(400.mhz().into());
config.pll1.q_ck = Some(100.mhz().into());
config
}

View File

@ -21,9 +21,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]
@ -77,15 +75,4 @@ fn main() -> ! {
})
}
fn config() -> Config {
let mut config = Config::default();
config.rcc = rcc_config();
config
}
fn rcc_config() -> rcc::Config {
let mut config = rcc::Config::default();
config.sys_ck = Some(400.mhz().into());
config.pll1.q_ck = Some(100.mhz().into());
config
}

View File

@ -6,6 +6,8 @@ use panic_probe as _;
pub use defmt::*;
use core::sync::atomic::{AtomicUsize, Ordering};
use embassy_stm32::Config;
use embassy_stm32::time::U32Ext;
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
}