diff --git a/beginner/apps/src/bin/stack_overflow.rs b/beginner/apps/src/bin/stack_overflow.rs new file mode 100644 index 0000000..e5930e8 --- /dev/null +++ b/beginner/apps/src/bin/stack_overflow.rs @@ -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 + } +} diff --git a/embedded-workshop-book/src/SUMMARY.md b/embedded-workshop-book/src/SUMMARY.md index 3a051f4..e91bab6 100644 --- a/embedded-workshop-book/src/SUMMARY.md +++ b/embedded-workshop-book/src/SUMMARY.md @@ -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) diff --git a/embedded-workshop-book/src/installation.md b/embedded-workshop-book/src/installation.md index edaa48b..d042a4f 100644 --- a/embedded-workshop-book/src/installation.md +++ b/embedded-workshop-book/src/installation.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