stm32: add rust stable support

This commit is contained in:
Dario Nieuwenhuis
2022-02-12 02:26:15 +01:00
parent f2eb438905
commit 340eb4eead
24 changed files with 149 additions and 52 deletions

View File

@ -5,14 +5,18 @@ name = "embassy-stm32l0-examples"
version = "0.1.0"
resolver = "2"
[features]
default = ["nightly"]
nightly = ["embassy-stm32/nightly", "embassy-lora", "lorawan-device", "lorawan-encoding"]
[dependencies]
embassy = { version = "0.1.0", path = "../../embassy", features = ["defmt"] }
embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["defmt", "stm32l072cz", "time-driver-any", "exti", "unstable-traits", "memory-x"] }
embassy-lora = { version = "0.1.0", path = "../../embassy-lora", features = ["sx127x", "time", "defmt"] }
embassy-lora = { version = "0.1.0", path = "../../embassy-lora", features = ["sx127x", "time", "defmt"], optional = true}
lorawan-device = { git = "https://github.com/ivajloip/rust-lorawan.git", rev = "0de1a2a31933f7c97887b5718c1755fa5ab93a42", default-features = false, features = ["async"] }
lorawan-encoding = { git = "https://github.com/ivajloip/rust-lorawan.git", rev = "0de1a2a31933f7c97887b5718c1755fa5ab93a42", default-features = false, features = ["default-crypto"] }
lorawan-device = { git = "https://github.com/ivajloip/rust-lorawan.git", rev = "0de1a2a31933f7c97887b5718c1755fa5ab93a42", default-features = false, features = ["async"], optional = true }
lorawan-encoding = { git = "https://github.com/ivajloip/rust-lorawan.git", rev = "0de1a2a31933f7c97887b5718c1755fa5ab93a42", default-features = false, features = ["default-crypto"], optional = true }
defmt = "0.3"
defmt-rtt = "0.3"

View File

@ -0,0 +1,54 @@
#![no_std]
#![no_main]
#[path = "../example_common.rs"]
mod example_common;
use example_common::*;
use core::mem;
use cortex_m_rt::entry;
use embassy::executor::raw::TaskStorage;
use embassy::executor::Executor;
use embassy::time::{Duration, Timer};
use embassy::util::Forever;
async fn run1() {
loop {
info!("BIG INFREQUENT TICK");
Timer::after(Duration::from_ticks(64000)).await;
}
}
async fn run2() {
loop {
info!("tick");
Timer::after(Duration::from_ticks(13000)).await;
}
}
static EXECUTOR: Forever<Executor> = Forever::new();
#[entry]
fn main() -> ! {
info!("Hello World!");
let _p = embassy_stm32::init(Default::default());
let executor = EXECUTOR.put(Executor::new());
let run1_task = TaskStorage::new();
let run2_task = TaskStorage::new();
// Safety: these variables do live forever if main never returns.
let run1_task = unsafe { make_static(&run1_task) };
let run2_task = unsafe { make_static(&run2_task) };
executor.run(|spawner| {
unwrap!(spawner.spawn(run1_task.spawn(|| run1())));
unwrap!(spawner.spawn(run2_task.spawn(|| run2())));
});
}
unsafe fn make_static<T>(t: &T) -> &'static T {
mem::transmute(t)
}