From 0e2ec97ce6d921455d0e59e9170e419988987948 Mon Sep 17 00:00:00 2001 From: Jorge Aparicio Date: Wed, 25 Apr 2018 07:54:05 +0200 Subject: [PATCH] make the hello example work --- Cargo.toml | 5 ++++- examples/hello.rs | 28 ++++++++++++++++------------ 2 files changed, 20 insertions(+), 13 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 3b64ba8..e40dde2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,13 +12,16 @@ version = "0.2.7" # cortex-m = "0.4.0" # cortex-m-rt = "0.4.0" cortex-m-rt = { git = "https://github.com/japaric/cortex-m-rt", branch = "stable" } -# cortex-m-semihosting = "0.2.0" # panic-loop = { path = "../panic-loop" } panic-abort = "0.1.1" # panic-semihosting = "0.1.0" # Uncomment for the allocator example. #alloc-cortex-m = "0.3.3" +[dependencies.cortex-m-semihosting] +default-features = false +version = "0.2.1" + # Uncomment for the device example. # [dependencies.stm32f103xx] # features = ["rt"] diff --git a/examples/hello.rs b/examples/hello.rs index 3d9d8c0..a4f1e5d 100644 --- a/examples/hello.rs +++ b/examples/hello.rs @@ -2,29 +2,33 @@ //! //! --- -#![feature(used)] +#![feature(asm)] +#![no_main] #![no_std] -extern crate cortex_m; +#[macro_use] extern crate cortex_m_rt; -extern crate cortex_m_semihosting; +extern crate cortex_m_semihosting as sh; extern crate panic_abort; // panicking behavior use core::fmt::Write; -use cortex_m::asm; -use cortex_m_semihosting::hio; +use sh::hio; -fn main() { +main!(main); + +fn main() -> ! { let mut stdout = hio::hstdout().unwrap(); writeln!(stdout, "Hello, world!").unwrap(); + + loop {} } -// As we are not using interrupts, we just register a dummy catch all handler -#[link_section = ".vector_table.interrupts"] -#[used] -static INTERRUPTS: [extern "C" fn(); 240] = [default_handler; 240]; +exception!(DefaultHandler, dh); -extern "C" fn default_handler() { - asm::bkpt(); +fn dh(_nr: u8) -> ! { + loop {} } + +// As we are not using interrupts, we just bind them all to the `DefaultHandler` exception handler +interrupts!(DefaultHandler);