diff options
| author | Emil Fresk <emil.fresk@gmail.com> | 2024-01-29 20:56:15 +0100 |
|---|---|---|
| committer | Emil Fresk <emil.fresk@gmail.com> | 2024-02-27 12:22:18 +0100 |
| commit | 27985009579e82673dcaf7a6a715fcf50c184863 (patch) | |
| tree | 8ae8f1cc9e8c6d2c2581467a4a537d8b84ae6552 /rtic-macros/src/codegen/bindings/cortex.rs | |
| parent | d2e84799c743eeb4b827d8da576be45ed43d6ece (diff) | |
Make RTIC 2 work on stable by using `main`'s stack as an allocator
Diffstat (limited to 'rtic-macros/src/codegen/bindings/cortex.rs')
| -rw-r--r-- | rtic-macros/src/codegen/bindings/cortex.rs | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/rtic-macros/src/codegen/bindings/cortex.rs b/rtic-macros/src/codegen/bindings/cortex.rs index ffa0245..69b5ee5 100644 --- a/rtic-macros/src/codegen/bindings/cortex.rs +++ b/rtic-macros/src/codegen/bindings/cortex.rs @@ -29,11 +29,35 @@ fn is_exception(name: &Ident) -> bool { | "SysTick" ) } + pub fn interrupt_ident() -> Ident { let span = Span::call_site(); Ident::new("interrupt", span) } +pub fn check_stack_overflow_before_init( + _app: &App, + _analysis: &CodegenAnalysis, +) -> Vec<TokenStream2> { + vec![quote!( + // Check for stack overflow using symbols from `cortex-m-rt`. + extern "C" { + pub static _stack_start: u32; + pub static __ebss: u32; + } + + let stack_start = &_stack_start as *const _ as u32; + let ebss = &__ebss as *const _ as u32; + + if stack_start > ebss { + // No flip-link usage, check the MSP for overflow. + if rtic::export::msp::read() <= ebss { + panic!("Stack overflow after allocating executors"); + } + } + )] +} + #[cfg(feature = "cortex-m-source-masking")] mod source_masking { use super::*; |
