diff options
| author | Dario Nieuwenhuis <[email protected]> | 2022-02-12 02:26:15 +0100 |
|---|---|---|
| committer | Dario Nieuwenhuis <[email protected]> | 2022-02-12 02:45:52 +0100 |
| commit | 340eb4eeadd1c7a022143d92bf6e3bb7ce141131 (patch) | |
| tree | 6081c324f814f1aa59f6bbf3c1f8cb51f208c950 /examples/stm32l0 | |
| parent | f2eb4389055ae6cf135168c1e5cb6ccd27800d63 (diff) | |
stm32: add rust stable support
Diffstat (limited to 'examples/stm32l0')
| -rw-r--r-- | examples/stm32l0/Cargo.toml | 10 | ||||
| -rw-r--r-- | examples/stm32l0/src/bin/raw_spawn.rs | 54 |
2 files changed, 61 insertions, 3 deletions
diff --git a/examples/stm32l0/Cargo.toml b/examples/stm32l0/Cargo.toml index f5d1a1d41..ce4efa52c 100644 --- a/examples/stm32l0/Cargo.toml +++ b/examples/stm32l0/Cargo.toml | |||
| @@ -5,14 +5,18 @@ name = "embassy-stm32l0-examples" | |||
| 5 | version = "0.1.0" | 5 | version = "0.1.0" |
| 6 | resolver = "2" | 6 | resolver = "2" |
| 7 | 7 | ||
| 8 | [features] | ||
| 9 | default = ["nightly"] | ||
| 10 | nightly = ["embassy-stm32/nightly", "embassy-lora", "lorawan-device", "lorawan-encoding"] | ||
| 11 | |||
| 8 | [dependencies] | 12 | [dependencies] |
| 9 | embassy = { version = "0.1.0", path = "../../embassy", features = ["defmt"] } | 13 | embassy = { version = "0.1.0", path = "../../embassy", features = ["defmt"] } |
| 10 | embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["defmt", "stm32l072cz", "time-driver-any", "exti", "unstable-traits", "memory-x"] } | 14 | embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["defmt", "stm32l072cz", "time-driver-any", "exti", "unstable-traits", "memory-x"] } |
| 11 | 15 | ||
| 12 | embassy-lora = { version = "0.1.0", path = "../../embassy-lora", features = ["sx127x", "time", "defmt"] } | 16 | embassy-lora = { version = "0.1.0", path = "../../embassy-lora", features = ["sx127x", "time", "defmt"], optional = true} |
| 13 | 17 | ||
| 14 | lorawan-device = { git = "https://github.com/ivajloip/rust-lorawan.git", rev = "0de1a2a31933f7c97887b5718c1755fa5ab93a42", default-features = false, features = ["async"] } | 18 | lorawan-device = { git = "https://github.com/ivajloip/rust-lorawan.git", rev = "0de1a2a31933f7c97887b5718c1755fa5ab93a42", default-features = false, features = ["async"], optional = true } |
| 15 | lorawan-encoding = { git = "https://github.com/ivajloip/rust-lorawan.git", rev = "0de1a2a31933f7c97887b5718c1755fa5ab93a42", default-features = false, features = ["default-crypto"] } | 19 | lorawan-encoding = { git = "https://github.com/ivajloip/rust-lorawan.git", rev = "0de1a2a31933f7c97887b5718c1755fa5ab93a42", default-features = false, features = ["default-crypto"], optional = true } |
| 16 | 20 | ||
| 17 | defmt = "0.3" | 21 | defmt = "0.3" |
| 18 | defmt-rtt = "0.3" | 22 | defmt-rtt = "0.3" |
diff --git a/examples/stm32l0/src/bin/raw_spawn.rs b/examples/stm32l0/src/bin/raw_spawn.rs new file mode 100644 index 000000000..9bb087c9e --- /dev/null +++ b/examples/stm32l0/src/bin/raw_spawn.rs | |||
| @@ -0,0 +1,54 @@ | |||
| 1 | #![no_std] | ||
| 2 | #![no_main] | ||
| 3 | |||
| 4 | #[path = "../example_common.rs"] | ||
| 5 | mod example_common; | ||
| 6 | use example_common::*; | ||
| 7 | |||
| 8 | use core::mem; | ||
| 9 | use cortex_m_rt::entry; | ||
| 10 | |||
| 11 | use embassy::executor::raw::TaskStorage; | ||
| 12 | use embassy::executor::Executor; | ||
| 13 | use embassy::time::{Duration, Timer}; | ||
| 14 | use embassy::util::Forever; | ||
| 15 | |||
| 16 | async fn run1() { | ||
| 17 | loop { | ||
| 18 | info!("BIG INFREQUENT TICK"); | ||
| 19 | Timer::after(Duration::from_ticks(64000)).await; | ||
| 20 | } | ||
| 21 | } | ||
| 22 | |||
| 23 | async fn run2() { | ||
| 24 | loop { | ||
| 25 | info!("tick"); | ||
| 26 | Timer::after(Duration::from_ticks(13000)).await; | ||
| 27 | } | ||
| 28 | } | ||
| 29 | |||
| 30 | static EXECUTOR: Forever<Executor> = Forever::new(); | ||
| 31 | |||
| 32 | #[entry] | ||
| 33 | fn main() -> ! { | ||
| 34 | info!("Hello World!"); | ||
| 35 | |||
| 36 | let _p = embassy_stm32::init(Default::default()); | ||
| 37 | let executor = EXECUTOR.put(Executor::new()); | ||
| 38 | |||
| 39 | let run1_task = TaskStorage::new(); | ||
| 40 | let run2_task = TaskStorage::new(); | ||
| 41 | |||
| 42 | // Safety: these variables do live forever if main never returns. | ||
| 43 | let run1_task = unsafe { make_static(&run1_task) }; | ||
| 44 | let run2_task = unsafe { make_static(&run2_task) }; | ||
| 45 | |||
| 46 | executor.run(|spawner| { | ||
| 47 | unwrap!(spawner.spawn(run1_task.spawn(|| run1()))); | ||
| 48 | unwrap!(spawner.spawn(run2_task.spawn(|| run2()))); | ||
| 49 | }); | ||
| 50 | } | ||
| 51 | |||
| 52 | unsafe fn make_static<T>(t: &T) -> &'static T { | ||
| 53 | mem::transmute(t) | ||
| 54 | } | ||
