From 24d6b9ed6c201f787521d24926551dca2610e3f4 Mon Sep 17 00:00:00 2001 From: Dario Nieuwenhuis Date: Thu, 14 Jan 2021 00:53:05 +0100 Subject: [PATCH] Build stm32 and stm32-examples in test script. Panic handler was missing, I had to add exaple_common.rs like in the nrf examples. --- embassy-stm32f4-examples/Cargo.toml | 6 ------ .../src/{ => bin}/serial.rs | 8 +++++--- embassy-stm32f4-examples/src/example_common.rs | 17 +++++++++++++++++ test-build.sh | 5 +++++ 4 files changed, 27 insertions(+), 9 deletions(-) rename embassy-stm32f4-examples/src/{ => bin}/serial.rs (90%) create mode 100644 embassy-stm32f4-examples/src/example_common.rs diff --git a/embassy-stm32f4-examples/Cargo.toml b/embassy-stm32f4-examples/Cargo.toml index 6502a77a..72fd6436 100644 --- a/embassy-stm32f4-examples/Cargo.toml +++ b/embassy-stm32f4-examples/Cargo.toml @@ -31,9 +31,3 @@ stm32f4xx-hal = { version = "0.8.3", features = ["rt", "stm32f405"], git = "htt futures = { version = "0.3.8", default-features = false, features = ["async-await"] } cortex-m-rtic = "0.5" rtt-target = { version = "0.3", features = ["cortex-m"] } - - - -[[bin]] -name = "serial" -path = "src/serial.rs" \ No newline at end of file diff --git a/embassy-stm32f4-examples/src/serial.rs b/embassy-stm32f4-examples/src/bin/serial.rs similarity index 90% rename from embassy-stm32f4-examples/src/serial.rs rename to embassy-stm32f4-examples/src/bin/serial.rs index ea049701..f3e0526c 100644 --- a/embassy-stm32f4-examples/src/serial.rs +++ b/embassy-stm32f4-examples/src/bin/serial.rs @@ -3,7 +3,9 @@ #![feature(trait_alias)] #![feature(type_alias_impl_trait)] -// extern crate panic_halt; +#[path = "../example_common.rs"] +mod example_common; +use example_common::{panic, *}; use cortex_m::singleton; use cortex_m_rt::entry; @@ -45,7 +47,7 @@ async fn run(dp: stm32::Peripherals, cp: cortex_m::Peripherals) { let buf = singleton!(: [u8; 30] = [0; 30]).unwrap(); buf[5] = 0x01; - serial.send(buf).await; + serial.send(buf).await.unwrap(); } static EXECUTOR: Forever = Forever::new(); @@ -56,7 +58,7 @@ fn main() -> ! { let cp = cortex_m::peripheral::Peripherals::take().unwrap(); let executor = EXECUTOR.put(Executor::new(cortex_m::asm::sev)); - executor.spawn(run(dp, cp)); + executor.spawn(run(dp, cp)).unwrap(); loop { executor.run(); diff --git a/embassy-stm32f4-examples/src/example_common.rs b/embassy-stm32f4-examples/src/example_common.rs new file mode 100644 index 00000000..ff4d8575 --- /dev/null +++ b/embassy-stm32f4-examples/src/example_common.rs @@ -0,0 +1,17 @@ +#![macro_use] + +use defmt_rtt as _; // global logger +use panic_probe as _; + +pub use defmt::*; + +use core::sync::atomic::{AtomicUsize, Ordering}; + +#[defmt::timestamp] +fn 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 +} diff --git a/test-build.sh b/test-build.sh index f67cc5b2..04e1a95e 100755 --- a/test-build.sh +++ b/test-build.sh @@ -23,3 +23,8 @@ set -euxo pipefail (cd embassy-nrf; cargo build --target thumbv7em-none-eabi --features 52840,log) (cd embassy-nrf; cargo build --target thumbv7em-none-eabi --features 52840,defmt) +# embassy-stm32f4 + +(cd embassy-stm32f4-examples; cargo build --target thumbv7em-none-eabi --bins) +(cd embassy-stm32f4; cargo build --target thumbv7em-none-eabi --features stm32f405) +(cd embassy-stm32f4; cargo build --target thumbv7em-none-eabi --features stm32f405,defmt)