Skip to content

Instantly share code, notes, and snippets.

@japaric
Last active April 30, 2017 04:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save japaric/7fdd6b7c1973f605f6903aa7513b7f21 to your computer and use it in GitHub Desktop.
Save japaric/7fdd6b7c1973f605f6903aa7513b7f21 to your computer and use it in GitHub Desktop.
cargo add alloc-cortex-m
xargo build --example hello
arm-none-eabi-gdb ..
# output: https://i.imgur.com/31iWvIc.png
// modified examples/hello.rs that uses the allocator
#![feature(collections)]
#![feature(used)]
#![no_std]
extern crate alloc_cortex_m;
#[macro_use]
extern crate collections;
#[macro_use]
extern crate cortex_m;
extern crate cortex_m_rt;
use cortex_m::asm;
fn main() {
extern {
// HEAP START
static mut _edata: usize;
}
// 1 KiB heap
unsafe {
alloc_cortex_m::init(&mut _edata, (&mut _edata as *mut _).offset(256));
}
let xs = vec![0, 1, 2];
hprintln!("{:?}", xs);
}
// As we are not using interrupts, we just register a dummy catch all handler
#[allow(dead_code)]
#[used]
#[link_section = ".rodata.interrupts"]
static INTERRUPTS: [extern "C" fn(); 240] = [default_handler; 240];
extern "C" fn default_handler() {
asm::bkpt();
}
[dependencies.collections] # <- this changed
[dependencies.compiler_builtins]
features = ["mem"]
git = "https://github.com/rust-lang-nursery/compiler-builtins"
stage = 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment