From ae0df60ec2624564311cb4ac4732d7f4c1204d50 Mon Sep 17 00:00:00 2001 From: Jorge Aparicio Date: Tue, 24 Nov 2020 17:21:15 +0100 Subject: [PATCH 1/2] use defmt::assert; add defmt::panic_handler --- Cargo.toml | 2 +- src/lib.rs | 10 +++++++++- testsuite/tests/test.rs | 5 +++-- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index b30dd96..6c72b7d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,7 +11,7 @@ members = ["testsuite"] [dependencies] cortex-m = "0.6.4" cortex-m-rt = "0.6.13" -defmt = "0.1.0" +defmt = "0.1.2" defmt-rtt = "0.1.0" panic-probe = { version = "0.1.0", features = ["print-defmt"] } # TODO(4) enter your HAL here diff --git a/src/lib.rs b/src/lib.rs index 52eb1bc..2905d1c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -3,10 +3,18 @@ use core::sync::atomic::{AtomicUsize, Ordering}; use defmt_rtt as _; // global logger -use panic_probe as _; // TODO(5) adjust HAL import // use some_hal as _; // memory layout +use panic_probe as _; + +// same panicking *behavior* as `panic-probe` but doesn't print a panic message +// this prevents the panic message being printed *twice* when `defmt::panic` is invoked +#[defmt::panic_handler] +fn panic() -> ! { + cortex_m::asm::udf() +} + #[defmt::timestamp] fn timestamp() -> u64 { static COUNT: AtomicUsize = AtomicUsize::new(0); diff --git a/testsuite/tests/test.rs b/testsuite/tests/test.rs index d1002ce..cb52264 100644 --- a/testsuite/tests/test.rs +++ b/testsuite/tests/test.rs @@ -2,6 +2,7 @@ #![no_main] use {{crate_name}} as _; // memory layout + panic handler +use defmt::{assert, assert_eq}; // See https://crates.io/crates/defmt-test/0.1.0 for more documentation (e.g. about the 'state' // feature) @@ -13,7 +14,7 @@ mod tests { } #[test] - fn assert_false() { - assert!(false, "TODO: write actual tests") + fn assert_eq() { + assert_eq!(24, 42, "TODO: write actual tests") } } From 0c324d336c24b1f65174302303f367ac3b26cb58 Mon Sep 17 00:00:00 2001 From: Jorge Aparicio Date: Mon, 30 Nov 2020 17:29:47 +0100 Subject: [PATCH 2/2] use defmt::panic instead of core::panic in example --- src/bin/panic.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/bin/panic.rs b/src/bin/panic.rs index efc755a..de9298f 100644 --- a/src/bin/panic.rs +++ b/src/bin/panic.rs @@ -7,5 +7,5 @@ use {{crate_name}} as _; // global logger + panicking-behavior + memory layout fn main() -> ! { defmt::info!("main"); - panic!() + defmt::panic!() }