diff --git a/macros/src/codegen.rs b/macros/src/codegen.rs index cf728a7d3f..21db14389c 100644 --- a/macros/src/codegen.rs +++ b/macros/src/codegen.rs @@ -66,9 +66,17 @@ pub fn app(app: &App, analysis: &Analysis, extra: &Extra) -> TokenStream2 { #(#pre_init_stmts)* - #call_init + #[inline(never)] + fn __rtic_init_resources(f: F) where F: FnOnce() { + f(); + } - #(#post_init_stmts)* + // Wrap late_init_stmts in a function to ensure that stack space is reclaimed. + __rtic_init_resources(||{ + #call_init + + #(#post_init_stmts)* + }); #call_idle }