From aa451a5ca7dc2d3531a255c68fce942de5a6865c Mon Sep 17 00:00:00 2001 From: Simon Hausmann Date: Thu, 9 Dec 2021 10:47:00 +0100 Subject: [PATCH] Make it possible to use flip-link flip-link (https://github.com/knurling-rs/flip-link) moves the stack to the bottom of the ram, so that we can reliably detect when running out of stack space. As per knurling-rs/flip-link#62 this requires using alloc-cortex-m differently, using a static allocation (in .bss) --- examples/printerdemo/rust/main.rs | 4 +--- .../rendering_backends/mcu/pico_st7789.rs | 12 +++++------- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/examples/printerdemo/rust/main.rs b/examples/printerdemo/rust/main.rs index bcaa5e4cc2b..8f4b1bae97d 100644 --- a/examples/printerdemo/rust/main.rs +++ b/examples/printerdemo/rust/main.rs @@ -72,9 +72,7 @@ pub fn main() { #[cfg(feature = "mcu-pico-st7789")] #[sixtyfps_rendering_backend_mcu::entry] fn main() -> ! { - sixtyfps_rendering_backend_mcu::init_board(sixtyfps_rendering_backend_mcu::BoardConfig { - heap_size: 120 * 1024, - }); + sixtyfps_rendering_backend_mcu::init_board(); printerdemo_main(); loop {} } diff --git a/sixtyfps_runtime/rendering_backends/mcu/pico_st7789.rs b/sixtyfps_runtime/rendering_backends/mcu/pico_st7789.rs index 6c4b91f1aec..8d30fa23beb 100644 --- a/sixtyfps_runtime/rendering_backends/mcu/pico_st7789.rs +++ b/sixtyfps_runtime/rendering_backends/mcu/pico_st7789.rs @@ -25,14 +25,13 @@ fn oom(_: core::alloc::Layout) -> ! { } use alloc_cortex_m::CortexMHeap; +const HEAP_SIZE: usize = 128 * 1024; +static mut HEAP: [u8; HEAP_SIZE] = [0; HEAP_SIZE]; + #[global_allocator] static ALLOCATOR: CortexMHeap = CortexMHeap::empty(); -pub struct BoardConfig { - pub heap_size: usize, -} - -pub fn init_board(config: BoardConfig) { +pub fn init_board() { let mut pac = pac::Peripherals::take().unwrap(); let core = pac::CorePeripherals::take().unwrap(); @@ -85,8 +84,7 @@ pub fn init_board(config: BoardConfig) { bl.set_high().unwrap(); } - let start = cortex_m_rt::heap_start() as usize; - unsafe { ALLOCATOR.init(start, config.heap_size) } + unsafe { ALLOCATOR.init(&mut HEAP as *const u8 as usize, core::mem::size_of_val(&HEAP)) } display.init(&mut delay).unwrap(); display.set_orientation(st7789::Orientation::Landscape).unwrap();