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

32 lines
596 B
Rust
Raw Normal View History

2021-01-22 14:01:48 +00:00
#![no_main]
#![no_std]
use cortex_m::asm;
use cortex_m_rt::entry;
2021-04-12 09:51:44 +00:00
// this imports `beginner/apps/lib.rs` to retrieve our global logger + panicking-behavior
use apps as _;
2021-01-22 14:01:48 +00:00
#[entry]
fn main() -> ! {
// board initialization
dk::init().unwrap();
2021-04-12 09:51:44 +00:00
defmt::info!("fib(100) = {:?}", fib(100));
2021-01-22 14:01:48 +00:00
loop {
asm::bkpt();
}
}
#[inline(never)]
fn fib(n: u32) -> u32 {
// allocate and initialize one kilobyte of stack memory to provoke stack overflow
let _use_stack = [0xAA; 1024];
if n < 2 {
1
} else {
fib(n - 1) + fib(n - 2) // recursion
}
}