alloc-cortex-m 0.2.1

A heap allocator for Cortex-M processors

Crate alloc_cortex_m [] [src]

A heap allocator for Cortex-M processors

Example

// Plug in the allocator crate
extern crate alloc_cortex_m;
extern crate collections;

use collections::Vec;

// These symbols come from a linker script
extern "C" {
    static mut _heap_start: usize;
    static mut _heap_end: usize;
}

#[no_mangle]
pub fn main() -> ! {
    // Initialize the heap BEFORE you use the allocator
    unsafe { alloc_cortex_m::init(&mut _heap_start, &mut _heap_end) }

    let mut xs = Vec::new();
    xs.push(1);
    // ...
}

And in your linker script, you might have something like:

/* space reserved for the stack */
_stack_size = 0x1000;

/* `.` is right after the .bss and .data sections */
_heap_start = .;
_heap_end = ORIGIN(SRAM) + LENGTH(SRAM) - _stack_size;

Functions

init

Initializes the heap