#![feature(alloc)]
#![feature(alloc_error_handler)]
#![feature(lang_items)]
#![no_main]
#![no_std]
extern crate alloc_cortex_m;
#[macro_use]
extern crate alloc;
extern crate cortex_m;
#[macro_use]
extern crate cortex_m_rt as rt;
extern crate cortex_m_semihosting as sh;
extern crate panic_semihosting;
use core::alloc::Layout;
use core::fmt::Write;
use alloc_cortex_m::CortexMHeap;
use cortex_m::asm;
use rt::ExceptionFrame;
use sh::hio;
#[global_allocator]
static ALLOCATOR: CortexMHeap = CortexMHeap::empty();
const HEAP_SIZE: usize = 1024;
entry!(main);
fn main() -> ! {
unsafe { ALLOCATOR.init(rt::heap_start() as usize, HEAP_SIZE) }
let xs = vec![0, 1, 2];
let mut stdout = hio::hstdout().unwrap();
writeln!(stdout, "{:?}", xs).unwrap();
loop {}
}
#[alloc_error_handler]
#[no_mangle]
pub fn alloc_error(_layout: Layout) -> ! {
asm::bkpt();
loop {}
}
exception!(HardFault, hard_fault);
fn hard_fault(ef: &ExceptionFrame) -> ! {
panic!("HardFault at {:#?}", ef);
}
exception!(*, default_handler);
fn default_handler(irqn: i16) {
panic!("Unhandled exception (IRQn = {})", irqn);
}