mirror of
https://github.com/ferrous-systems/embedded-trainings-2020.git
synced 2025-01-25 07:18:08 +00:00
wip: move beginner to defmt
This commit is contained in:
parent
af4b9e3b76
commit
6bbd0c1e45
9 changed files with 40 additions and 17 deletions
|
@ -2,6 +2,7 @@
|
|||
# (..)
|
||||
rustflags = [
|
||||
"-C", "linker=flip-link", # adds stack overflow protection
|
||||
"-C", "link-arg=-Tdefmt.x", # defmt support
|
||||
# (..)
|
||||
]
|
||||
|
||||
|
|
|
@ -10,7 +10,6 @@ cortex-m = "0.6.4"
|
|||
cortex-m-rt = "0.6.13"
|
||||
dk = { path = "../../boards/dk", features = ["beginner"] }
|
||||
heapless = "0.5.5"
|
||||
panic-log = { path = "../../common/panic-log" }
|
||||
panic-probe = { version = "0.2.0", features = ["print-defmt"] }
|
||||
defmt = "0.2.0"
|
||||
defmt-rtt = "0.2.0"
|
||||
|
@ -18,7 +17,7 @@ defmt-rtt = "0.2.0"
|
|||
# optimize code in both profiles
|
||||
[profile.dev]
|
||||
codegen-units = 1
|
||||
debug = 1
|
||||
debug = 2
|
||||
debug-assertions = true # !
|
||||
incremental = false
|
||||
lto = "fat"
|
||||
|
|
|
@ -4,7 +4,8 @@
|
|||
use core::time::Duration;
|
||||
|
||||
use cortex_m_rt::entry;
|
||||
use panic_log as _; // panic handler
|
||||
// this imports `beginner/apps/lib.rs` to retrieve our global logger + panicking-behavior
|
||||
use apps as _;
|
||||
|
||||
#[entry]
|
||||
fn main() -> ! {
|
||||
|
@ -19,7 +20,7 @@ fn main() -> ! {
|
|||
for _ in 0..10 {
|
||||
led.toggle();
|
||||
timer.wait(Duration::from_secs(1));
|
||||
log::info!("LED toggled at {:?}", dk::uptime());
|
||||
defmt::debug!("LED toggled at {:?}", dk::uptime());
|
||||
}
|
||||
|
||||
dk::exit()
|
||||
|
|
|
@ -6,8 +6,8 @@
|
|||
|
||||
use cortex_m::asm;
|
||||
use cortex_m_rt::entry;
|
||||
use defmt_rtt as _; // global logger
|
||||
use panic_probe as _; // the panicking behavior
|
||||
// this imports `beginner/apps/lib.rs` to retrieve our global logger + panicking-behavior
|
||||
use apps as _;
|
||||
|
||||
// the custom entry point
|
||||
// vvvvv
|
||||
|
|
|
@ -3,7 +3,8 @@
|
|||
|
||||
use cortex_m::asm;
|
||||
use cortex_m_rt::entry;
|
||||
use panic_log as _; // the panicking behavior
|
||||
// this imports `beginner/apps/lib.rs` to retrieve our global logger + panicking-behavior
|
||||
use apps as _;
|
||||
|
||||
#[entry]
|
||||
fn main() -> ! {
|
||||
|
|
|
@ -3,7 +3,9 @@
|
|||
|
||||
use cortex_m::asm;
|
||||
use cortex_m_rt::entry;
|
||||
use panic_log as _; // the panicking behavior
|
||||
// this imports `beginner/apps/lib.rs` to retrieve our global logger + panicking-behavior
|
||||
use apps as _;
|
||||
|
||||
|
||||
#[entry]
|
||||
fn main() -> ! {
|
||||
|
@ -28,7 +30,7 @@ fn bar() {
|
|||
let array = [0, 1, 2];
|
||||
let x = array[i]; // out of bounds access
|
||||
|
||||
log::info!("{}", x);
|
||||
defmt::info!("{}", x);
|
||||
}
|
||||
|
||||
fn index() -> usize {
|
||||
|
|
|
@ -4,7 +4,8 @@
|
|||
|
||||
use cortex_m_rt::entry;
|
||||
use dk::ieee802154::{Channel, Packet};
|
||||
use panic_log as _; // the panicking behavior
|
||||
// this imports `beginner/apps/lib.rs` to retrieve our global logger + panicking-behavior
|
||||
use apps as _;
|
||||
|
||||
const TEN_MS: u32 = 10_000;
|
||||
|
||||
|
@ -37,15 +38,15 @@ fn main() -> ! {
|
|||
if packet.len() == 1 {
|
||||
let destination = packet[0];
|
||||
|
||||
log::info!("{} -> {}", source, destination);
|
||||
defmt::info!("{} -> {}", source, destination);
|
||||
// or cast to `char` for a more readable output
|
||||
log::info!("{:?} -> {:?}", source as char, destination as char);
|
||||
defmt::info!("{:?} -> {:?}", source as char, destination as char);
|
||||
} else {
|
||||
log::error!("response packet was not a single byte");
|
||||
defmt::error!("response packet was not a single byte");
|
||||
dk::exit()
|
||||
}
|
||||
} else {
|
||||
log::error!("no response or response packet was corrupted");
|
||||
defmt::error!("no response or response packet was corrupted");
|
||||
dk::exit()
|
||||
}
|
||||
|
||||
|
|
|
@ -7,7 +7,8 @@ use cortex_m_rt::entry;
|
|||
// lookup performance when the dictionary contains a large number of items but performance is
|
||||
// not important for this exercise
|
||||
use heapless::{consts, LinearMap};
|
||||
use panic_log as _; // the panicking behavior
|
||||
// this imports `beginner/apps/lib.rs` to retrieve our global logger + panicking-behavior
|
||||
use apps as _;
|
||||
|
||||
#[entry]
|
||||
fn main() -> ! {
|
||||
|
@ -25,9 +26,9 @@ fn main() -> ! {
|
|||
let key = b'A';
|
||||
let value = dict[&key]; // the key needs to be passed by reference
|
||||
|
||||
log::info!("{} -> {}", key, value);
|
||||
defmt::info!("{} -> {}", key, value);
|
||||
// more readable
|
||||
log::info!("{:?} -> {:?}", key as char, value as char);
|
||||
defmt::info!("{:?} -> {:?}", key as char, value as char);
|
||||
|
||||
// TODO try another insertion
|
||||
// TODO try looking up a key not contained in the dictionary
|
||||
|
|
17
beginner/apps/src/lib.rs
Normal file
17
beginner/apps/src/lib.rs
Normal file
|
@ -0,0 +1,17 @@
|
|||
#![no_std]
|
||||
|
||||
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()
|
||||
}
|
||||
|
||||
/// Terminates the application and makes `probe-run` exit with exit-code = 0
|
||||
pub fn exit() -> ! {
|
||||
loop {
|
||||
cortex_m::asm::bkpt();
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue