mirror of
https://github.com/ferrous-systems/embedded-trainings-2020.git
synced 2025-01-09 07:45:34 +00:00
add stack_overflow exercise
This commit is contained in:
parent
816ab161fc
commit
514292aaab
3 changed files with 37 additions and 0 deletions
30
beginner/apps/src/bin/stack_overflow.rs
Normal file
30
beginner/apps/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
|
||||
}
|
||||
}
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue