mirror of
https://github.com/ferrous-systems/embedded-trainings-2020.git
synced 2025-01-10 16:25:37 +00:00
add stack_overflow.rs
This commit is contained in:
parent
3d48894186
commit
c54d03e19b
1 changed files with 30 additions and 0 deletions
30
advanced/firmware/src/bin/stack_overflow.rs
Normal file
30
advanced/firmware/src/bin/stack_overflow.rs
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
#![no_main]
|
||||||
|
#![no_std]
|
||||||
|
|
||||||
|
use cortex_m::asm;
|
||||||
|
use cortex_m_rt::entry;
|
||||||
|
use panic_log as _; // panic handler
|
||||||
|
|
||||||
|
#[entry]
|
||||||
|
fn main() -> ! {
|
||||||
|
// board initialization
|
||||||
|
dk::init().unwrap();
|
||||||
|
|
||||||
|
log::info!("fib(100) = {:?}", fib(100));
|
||||||
|
|
||||||
|
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
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue