update defmt deps to v0.3 (#56)

* bump defmt to v0.3

remove Cargo features which are no longer needed

* remove `timestamp!`

it's no longer mandatory and a monotonic counter does not add much value given that `defmt-rtt`
works by disabling interrupts so one won't see logs out of order anyways (which would the case for a
lock-free multi-channel `Logger`)

* use println! in most the examples

so that all examples print something when `DEFMT_LOG` is unset

* make overflow example terminate in less steps

also include an estimate of the stack pointer to show the stack grows downwards towards the RAM
boundary
This commit is contained in:
Jorge Aparicio
2021-11-10 04:46:56 +01:00
committed by GitHub
parent 265b7f2878
commit 733a38a272
9 changed files with 29 additions and 61 deletions
+5 -20
View File
@@ -9,29 +9,14 @@ version = "0.1.0"
members = ["testsuite"] members = ["testsuite"]
[dependencies] [dependencies]
cortex-m = "0.7.1" cortex-m = "0.7.3"
cortex-m-rt = "0.6.13" cortex-m-rt = "0.7.0"
defmt = "0.2.0" defmt = "0.3.0"
defmt-rtt = "0.2.0" defmt-rtt = "0.3.0"
panic-probe = { version = "0.2.0", features = ["print-defmt"] } panic-probe = { version = "0.3.0", features = ["print-defmt"] }
# TODO(4) enter your HAL here # TODO(4) enter your HAL here
# some-hal = "1.2.3" # some-hal = "1.2.3"
[features]
# set logging levels here
default = [
"defmt-default",
# "dependency-a/defmt-trace",
]
# do NOT modify these features
defmt-default = []
defmt-trace = []
defmt-debug = []
defmt-info = []
defmt-warn = []
defmt-error = []
# cargo build/run # cargo build/run
[profile.dev] [profile.dev]
codegen-units = 1 codegen-units = 1
+1 -1
View File
@@ -7,7 +7,7 @@ use {{crate_name}} as _; // global logger + panicking-behavior + memory layout
fn main() -> ! { fn main() -> ! {
// value of the FREQUENCY register (nRF52840 device; RADIO peripheral) // value of the FREQUENCY register (nRF52840 device; RADIO peripheral)
let frequency: u32 = 276; let frequency: u32 = 276;
defmt::debug!("FREQUENCY: {0=0..7}, MAP: {0=8..9}", frequency); defmt::println!("FREQUENCY: {0=0..7}, MAP: {0=8..9}", frequency);
{{crate_name}}::exit() {{crate_name}}::exit()
} }
+6 -3
View File
@@ -17,10 +17,13 @@ struct S2 {
#[cortex_m_rt::entry] #[cortex_m_rt::entry]
fn main() -> ! { fn main() -> ! {
let s = S1 { x: 42, y: S2 { z: 43 } }; let s = S1 {
defmt::info!("s={:?}", s); x: 42,
y: S2 { z: 43 },
};
defmt::println!("s={:?}", s);
let x = 42; let x = 42;
defmt::info!("x={=u8}", x); defmt::println!("x={=u8}", x);
{{crate_name}}::exit() {{crate_name}}::exit()
} }
+1 -1
View File
@@ -5,7 +5,7 @@ use {{crate_name}} as _; // global logger + panicking-behavior + memory layout
#[cortex_m_rt::entry] #[cortex_m_rt::entry]
fn main() -> ! { fn main() -> ! {
defmt::info!("Hello, world!"); defmt::println!("Hello, world!");
{{crate_name}}::exit() {{crate_name}}::exit()
} }
+2
View File
@@ -5,6 +5,8 @@ use {{crate_name}} as _; // global logger + panicking-behavior + memory layout
#[cortex_m_rt::entry] #[cortex_m_rt::entry]
fn main() -> ! { fn main() -> ! {
// try setting the DEFMT_LOG environment variable
// e.g. `export DEFMT_LOG=info` or `DEFMT_LOG=trace cargo rb levels`
defmt::info!("info"); defmt::info!("info");
defmt::trace!("trace"); defmt::trace!("trace");
defmt::warn!("warn"); defmt::warn!("warn");
+6 -3
View File
@@ -10,12 +10,15 @@ fn main() -> ! {
} }
fn ack(m: u32, n: u32) -> u32 { fn ack(m: u32, n: u32) -> u32 {
defmt::info!("ack(m={=u32}, n={=u32})", m, n); // waste stack space to trigger a stack overflow
let mut big = [2; 512]; let mut buffer = [0u8; 16 * 1024];
// estimate of the Stack Pointer register
let sp = buffer.as_mut_ptr();
defmt::println!("ack(m={=u32}, n={=u32}, SP={:x})", m, n, sp);
if m == 0 { if m == 0 {
n + 1 n + 1
} else { } else {
big[100] += 1;
if n == 0 { if n == 0 {
ack(m - 1, 1) ack(m - 1, 1)
} else { } else {
+1 -1
View File
@@ -5,7 +5,7 @@ use {{crate_name}} as _; // global logger + panicking-behavior + memory layout
#[cortex_m_rt::entry] #[cortex_m_rt::entry]
fn main() -> ! { fn main() -> ! {
defmt::info!("main"); defmt::println!("main");
defmt::panic!() defmt::panic!()
} }
+1 -10
View File
@@ -1,8 +1,7 @@
#![no_std] #![no_std]
use core::sync::atomic::{AtomicUsize, Ordering};
use defmt_rtt as _; // global logger use defmt_rtt as _; // global logger
// TODO(5) adjust HAL import // TODO(5) adjust HAL import
// use some_hal as _; // memory layout // use some_hal as _; // memory layout
@@ -15,14 +14,6 @@ fn panic() -> ! {
cortex_m::asm::udf() cortex_m::asm::udf()
} }
static COUNT: AtomicUsize = AtomicUsize::new(0);
defmt::timestamp!("{=usize}", {
// NOTE(no-CAS) `timestamps` runs with interrupts disabled
let n = COUNT.load(Ordering::Relaxed);
COUNT.store(n + 1, Ordering::Relaxed);
n
});
/// Terminates the application and makes `probe-run` exit with exit-code = 0 /// Terminates the application and makes `probe-run` exit with exit-code = 0
pub fn exit() -> ! { pub fn exit() -> ! {
loop { loop {
+6 -22
View File
@@ -15,25 +15,9 @@ harness = false
[dependencies] [dependencies]
{{project-name}} = { path = ".." } {{project-name}} = { path = ".." }
cortex-m = "0.7.1" cortex-m = "0.7.3"
cortex-m-rt = "0.6.12" cortex-m-rt = "0.7.0"
defmt = "0.2.0" defmt = "0.3.0"
defmt-rtt = "0.2.0" defmt-rtt = "0.3.0"
defmt-test = "0.2.0" defmt-test = "0.3.0"
panic-probe = { version = "0.2.0", features = ["print-defmt"] } panic-probe = { version = "0.3.0", features = ["print-defmt"] }
[features]
# set logging levels here
default = [
# in tests, enable all logs
"defmt-trace",
# "dependency-a/defmt-trace",
]
# do NOT modify these features
defmt-default = []
defmt-trace = []
defmt-debug = []
defmt-info = []
defmt-warn = []
defmt-error = []