add embassy::main and implement for stm32f4
This commit is contained in:
@ -38,6 +38,7 @@ stm32f479 = ["stm32f4xx-hal/stm32f469", "embassy-stm32f4/stm32f469"]
|
||||
embassy = { version = "0.1.0", path = "../embassy", features = ["defmt", "defmt-trace"] }
|
||||
embassy-traits = { version = "0.1.0", path = "../embassy-traits", features = ["defmt"] }
|
||||
embassy-stm32f4 = { version = "*", path = "../embassy-stm32f4" }
|
||||
embassy-stm32 = { version = "*", path = "../embassy-stm32" }
|
||||
|
||||
defmt = "0.2.0"
|
||||
defmt-rtt = "0.2.0"
|
||||
|
@ -8,19 +8,19 @@
|
||||
mod example_common;
|
||||
use example_common::*;
|
||||
|
||||
use cortex_m_rt::entry;
|
||||
use defmt::panic;
|
||||
use embassy::executor::{task, Executor};
|
||||
use embassy;
|
||||
use embassy::executor::Spawner;
|
||||
use embassy::task;
|
||||
use embassy::time::{Duration, Timer};
|
||||
use embassy::util::Forever;
|
||||
use embassy_stm32f4::{interrupt, pac, rtc};
|
||||
use stm32f4xx_hal::prelude::*;
|
||||
use embassy_stm32f4;
|
||||
use embassy_stm32f4::hal;
|
||||
|
||||
#[task]
|
||||
async fn run1() {
|
||||
loop {
|
||||
info!("BIG INFREQUENT TICK");
|
||||
Timer::after(Duration::from_ticks(32768 * 2)).await;
|
||||
Timer::after(Duration::from_ticks(32768 * 2 as u64)).await;
|
||||
}
|
||||
}
|
||||
|
||||
@ -28,40 +28,13 @@ async fn run1() {
|
||||
async fn run2() {
|
||||
loop {
|
||||
info!("tick");
|
||||
Timer::after(Duration::from_ticks(13000)).await;
|
||||
Timer::after(Duration::from_ticks(13000 as u64)).await;
|
||||
}
|
||||
}
|
||||
|
||||
static RTC: Forever<rtc::RTC<pac::TIM2>> = Forever::new();
|
||||
static ALARM: Forever<rtc::Alarm<pac::TIM2>> = Forever::new();
|
||||
static EXECUTOR: Forever<Executor> = Forever::new();
|
||||
#[embassy::main(use_hse = 16)]
|
||||
async fn main(spawner: Spawner) {
|
||||
let (dp, clocks) = embassy_stm32::Peripherals::take().unwrap();
|
||||
|
||||
#[entry]
|
||||
fn main() -> ! {
|
||||
info!("Hello World!");
|
||||
|
||||
let p = unwrap!(pac::Peripherals::take());
|
||||
|
||||
p.RCC.ahb1enr.modify(|_, w| w.dma1en().enabled());
|
||||
let rcc = p.RCC.constrain();
|
||||
let clocks = rcc.cfgr.freeze();
|
||||
|
||||
p.DBGMCU.cr.modify(|_, w| {
|
||||
w.dbg_sleep().set_bit();
|
||||
w.dbg_standby().set_bit();
|
||||
w.dbg_stop().set_bit()
|
||||
});
|
||||
|
||||
let rtc = RTC.put(rtc::RTC::new(p.TIM2, interrupt::take!(TIM2), clocks));
|
||||
rtc.start();
|
||||
|
||||
unsafe { embassy::time::set_clock(rtc) };
|
||||
|
||||
let alarm = ALARM.put(rtc.alarm1());
|
||||
let executor = EXECUTOR.put(Executor::new());
|
||||
executor.set_alarm(alarm);
|
||||
executor.run(|spawner| {
|
||||
unwrap!(spawner.spawn(run1()));
|
||||
unwrap!(spawner.spawn(run2()));
|
||||
});
|
||||
spawner.spawn(run1()).unwrap();
|
||||
}
|
||||
|
Reference in New Issue
Block a user