Created
December 23, 2020 20:24
-
-
Save patrickod/ec35c2fe8d9d6a0a44270a21b8b8bf9f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12:20:47 patrickod@finn feather-test main ? cargo run 1 ↵ | |
Compiling feather-test v0.1.0 (/home/patrickod/code/lsm6ds33/feather-test) | |
Finished dev [optimized + debuginfo] target(s) in 0.31s | |
Running `probe-run --chip nRF52840_xxAA target/thumbv7em-none-eabihf/debug/feather-test` | |
(HOST) INFO flashing program (9.29 KiB) | |
(HOST) INFO success! | |
──────────────────────────────────────────────────────────────────────────────── | |
RTT error: Error communicating with probe: An error with the usage of the probe occured | |
stack backtrace: | |
0: Reset | |
at /home/patrickod/.cargo/registry/src/github.com-1ecc6299db9ec823/cortex-m-rt-0.6.13/src/lib.rs:497 | |
Error: bug? LR (0xfa2ef000) didn't have the Thumb bit set |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[target.'cfg(all(target_arch = "arm", target_os = "none"))'] | |
runner = "probe-run --chip nRF52840_xxAA" | |
rustflags = [ | |
"-C", "linker=flip-link", | |
"-C", "link-arg=-Tlink.x", | |
"-C", "link-arg=-Tdefmt.x", | |
# This is needed if your flash or ram addresses are not aligned to 0x10000 in memory.x | |
# See https://github.com/rust-embedded/cortex-m-quickstart/pull/95 | |
"-C", "link-arg=--nmagic", | |
] | |
[build] | |
target = "thumbv7em-none-eabihf" # Cortex-M4F and Cortex-M7F (with FPU) | |
[alias] | |
rb = "run --bin" | |
rrb = "run --release --bin" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#![no_std] | |
#![no_main] | |
use core::sync::atomic::{AtomicUsize, Ordering}; | |
use defmt_rtt as _; // global logger | |
use lsm6ds33::LSM6DS33; | |
use panic_probe as _; | |
use nrf52840_hal::{ | |
gpio::p0::Parts as P0Parts, | |
pac::Peripherals, | |
twim::{Frequency as TwimFrequency, Pins as TwimPins}, | |
Twim, | |
}; | |
// 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); | |
// NOTE(no-CAS) `timestamps` runs with interrupts disabled | |
let n = COUNT.load(Ordering::Relaxed); | |
COUNT.store(n + 1, Ordering::Relaxed); | |
n as u64 | |
} | |
/// Terminates the application and makes `probe-run` exit with exit-code = 0 | |
pub fn exit() -> ! { | |
loop { | |
cortex_m::asm::bkpt(); | |
} | |
} | |
#[cortex_m_rt::entry] | |
fn main() -> ! { | |
match inner_main() { | |
Ok(()) => cortex_m::peripheral::SCB::sys_reset(), | |
Err(e) => panic!(e), | |
} | |
} | |
fn inner_main() -> Result<(), &'static str> { | |
let board = Peripherals::take().ok_or("unable to load board")?; | |
let p0 = P0Parts::new(board.P0); | |
let scl = p0.p0_11.into_floating_input().degrade(); | |
let sda = p0.p0_12.into_floating_input().degrade(); | |
let i2c = Twim::new(board.TWIM0, TwimPins { sda, scl }, TwimFrequency::K100); | |
let mut sensor = match LSM6DS33::new(i2c) { | |
Ok(lsm6ds33) => lsm6ds33, | |
Err(_) => return Err("unable to init LSM6DS33"), | |
}; | |
let who_am_i = match sensor.who_am_i() { | |
Ok(id) => id, | |
Err(_) => return Err("unable to query who_am_i register"), | |
}; | |
defmt::info!("received who_am_i: {:?}", who_am_i); | |
Ok(()) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment