-
-
Save japaric/7fdd6b7c1973f605f6903aa7513b7f21 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
cargo add alloc-cortex-m | |
xargo build --example hello | |
arm-none-eabi-gdb .. | |
# output: https://i.imgur.com/31iWvIc.png |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[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