initial commit

This commit is contained in:
Jorge Aparicio
2020-08-21 12:02:11 +02:00
commit df96204a61
13 changed files with 479 additions and 0 deletions
+13
View File
@@ -0,0 +1,13 @@
#![no_main]
#![no_std]
use {{crate_name}} as _; // global logger + panicking-behavior + memory layout
#[cortex_m_rt::entry]
fn main() -> ! {
// value of the FREQUENCY register (nRF52840 device; RADIO peripheral)
let frequency: u32 = 276;
defmt::debug!("FREQUENCY: {0:0..7}, MAP: {0:8..9}", frequency);
{{crate_name}}::exit()
}
+26
View File
@@ -0,0 +1,26 @@
#![no_main]
#![no_std]
use {{crate_name}} as _; // global logger + panicking-behavior + memory layout
use defmt::Format; // <- derive attribute
#[derive(Format)]
struct S1<T> {
x: u8,
y: T,
}
#[derive(Format)]
struct S2 {
z: u8,
}
#[cortex_m_rt::entry]
fn main() -> ! {
let s = S1 { x: 42, y: S2 { z: 43 } };
defmt::info!("s={:?}", s);
let x = 42;
defmt::info!("x={:u8}", x);
{{crate_name}}::exit()
}
+11
View File
@@ -0,0 +1,11 @@
#![no_main]
#![no_std]
use {{crate_name}} as _; // global logger + panicking-behavior + memory layout
#[cortex_m_rt::entry]
fn main() -> ! {
defmt::info!("Hello, world!");
{{crate_name}}::exit()
}
+15
View File
@@ -0,0 +1,15 @@
#![no_main]
#![no_std]
use {{crate_name}} as _; // global logger + panicking-behavior + memory layout
#[cortex_m_rt::entry]
fn main() -> ! {
defmt::info!("info");
defmt::trace!("trace");
defmt::warn!("warn");
defmt::debug!("debug");
defmt::error!("error");
{{crate_name}}::exit()
}
+11
View File
@@ -0,0 +1,11 @@
#![no_main]
#![no_std]
use {{crate_name}} as _; // global logger + panicking-behavior + memory layout
#[cortex_m_rt::entry]
fn main() -> ! {
defmt::info!("main");
panic!()
}
+41
View File
@@ -0,0 +1,41 @@
#![no_std]
use core::sync::atomic::{AtomicUsize, Ordering};
use defmt_rtt as _; // global logger
// TODO(5) adjust HAL import
// use some_hal as _; // memory layout
#[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
}
#[panic_handler] // panicking behavior
fn panic(info: &core::panic::PanicInfo) -> ! {
if let Some(loc) = info.location() {
defmt::error!(
"panicked at {:str}:{:u32}:{:u32}",
loc.file(),
loc.line(),
loc.column()
)
} else {
// no location info
defmt::error!("panicked")
}
exit()
}
/// Terminates the application and makes `probe-run` exit with exit-code = 0
pub fn exit() -> ! {
loop {
cortex_m::asm::bkpt();
}
}