Skip to content

Commit ae0df60

Browse files
committed
use defmt::assert; add defmt::panic_handler
1 parent 647289a commit ae0df60

File tree

3 files changed

+13
-4
lines changed

3 files changed

+13
-4
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ members = ["testsuite"]
1111
[dependencies]
1212
cortex-m = "0.6.4"
1313
cortex-m-rt = "0.6.13"
14-
defmt = "0.1.0"
14+
defmt = "0.1.2"
1515
defmt-rtt = "0.1.0"
1616
panic-probe = { version = "0.1.0", features = ["print-defmt"] }
1717
# TODO(4) enter your HAL here

src/lib.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,18 @@
33
use core::sync::atomic::{AtomicUsize, Ordering};
44

55
use defmt_rtt as _; // global logger
6-
use panic_probe as _;
76
// TODO(5) adjust HAL import
87
// use some_hal as _; // memory layout
98

9+
use panic_probe as _;
10+
11+
// same panicking *behavior* as `panic-probe` but doesn't print a panic message
12+
// this prevents the panic message being printed *twice* when `defmt::panic` is invoked
13+
#[defmt::panic_handler]
14+
fn panic() -> ! {
15+
cortex_m::asm::udf()
16+
}
17+
1018
#[defmt::timestamp]
1119
fn timestamp() -> u64 {
1220
static COUNT: AtomicUsize = AtomicUsize::new(0);

testsuite/tests/test.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#![no_main]
33

44
use {{crate_name}} as _; // memory layout + panic handler
5+
use defmt::{assert, assert_eq};
56

67
// See https://crates.io/crates/defmt-test/0.1.0 for more documentation (e.g. about the 'state'
78
// feature)
@@ -13,7 +14,7 @@ mod tests {
1314
}
1415

1516
#[test]
16-
fn assert_false() {
17-
assert!(false, "TODO: write actual tests")
17+
fn assert_eq() {
18+
assert_eq!(24, 42, "TODO: write actual tests")
1819
}
1920
}

0 commit comments

Comments
 (0)