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

42 lines
622 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;
2021-04-08 09:27:00 +00:00
// this imports `beginner/apps/lib.rs` to retrieve our global logger + panicking-behavior
2022-01-07 16:24:21 +00:00
// use apps as _;
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
2022-01-07 16:24:21 +00:00
defmt::println!("{}", 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) -> ! {
2021-04-08 09:27:00 +00:00
defmt::panic!("{}", info);
}