embedded-trainings-2020/beginner/apps/src/bin/panic.rs

42 lines
576 B
Rust
Raw Normal View History

2020-06-09 09:52:27 +00:00
#![no_main]
#![no_std]
use cortex_m::asm;
use cortex_m_rt::entry;
// use apps as _; // this defines the panicking behaviour
2021-04-08 12:16:26 +00:00
2020-06-09 09:52:27 +00:00
#[entry]
fn main() -> ! {
dk::init().unwrap();
foo();
loop {
asm::bkpt();
}
}
#[inline(never)]
fn foo() {
asm::nop();
bar();
}
#[inline(never)]
fn bar() {
2020-07-16 14:21:49 +00:00
let i = index();
2020-06-09 09:52:27 +00:00
let array = [0, 1, 2];
let x = array[i]; // out of bounds access
2021-04-08 12:16:26 +00:00
defmt::info!("{}", x);
2020-06-09 09:52:27 +00:00
}
2020-07-16 14:21:49 +00:00
fn index() -> usize {
3
}
#[panic_handler]
fn panic(info: &core::panic::PanicInfo) -> ! {
defmt::panic!("lalal {}", info);
}