add stack_overflow exercise

This commit is contained in:
Lotte Steenbrink 2021-01-22 15:01:48 +01:00
parent 816ab161fc
commit 514292aaab
3 changed files with 37 additions and 0 deletions

View 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
}
}

View file

@ -57,6 +57,7 @@
- [Inspecting the Descriptors](./inspecting-descriptors.md)
- [Getting it Configured](./getting-device-configured.md)
- [Next Steps](./advanced-next-steps.md)
- [Stack Overflow Protection](./stack-overflow-protection.md)
- [References and Resources](./references-resources.md)
- [Tooltips](./tooltips.md)
- [Troubleshooting](./troubleshooting.md)

View file

@ -176,6 +176,12 @@ Leave the processes running in the background.
#### Advanced workshop
```console
$ cargo install flip-link
(..)
Installed package `flip-link v0.1.2` (..)
```
Change to the `tools` folder and run these commands:
```console