Skip to content

Commit

Permalink
Make it possible to use flip-link
Browse files Browse the repository at this point in the history
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)
  • Loading branch information
tronical committed Dec 22, 2021
1 parent 3fc88d4 commit c28a7c6
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 10 deletions.
4 changes: 1 addition & 3 deletions examples/printerdemo/rust/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,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 {}
}
Expand Down
12 changes: 5 additions & 7 deletions sixtyfps_runtime/rendering_backends/mcu/pico_st7789.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,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();

Expand Down Expand Up @@ -78,8 +77,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();
Expand Down

0 comments on commit c28a7c6

Please sign in to comment.