Merge pull request #57 from rust-embedded/sh
use hprint macros and NVIC::pend; fix allocator example
This commit is contained in:
@@ -6,9 +6,9 @@ name = "{{project-name}}"
|
||||
version = "0.1.0"
|
||||
|
||||
[dependencies]
|
||||
cortex-m = "0.5.7"
|
||||
cortex-m-rt = "0.6.3"
|
||||
cortex-m-semihosting = "0.3.1"
|
||||
cortex-m = "0.5.8"
|
||||
cortex-m-rt = "0.6.5"
|
||||
cortex-m-semihosting = "0.3.2"
|
||||
panic-halt = "0.2.0"
|
||||
|
||||
# Uncomment for the panic example.
|
||||
|
||||
@@ -14,16 +14,16 @@
|
||||
#![no_main]
|
||||
#![no_std]
|
||||
|
||||
extern crate alloc;
|
||||
extern crate panic_halt;
|
||||
|
||||
use self::alloc::vec;
|
||||
use core::alloc::Layout;
|
||||
use core::fmt::Write;
|
||||
|
||||
use alloc::vec;
|
||||
use alloc_cortex_m::CortexMHeap;
|
||||
use cortex_m::asm;
|
||||
use cortex_m_rt::entry;
|
||||
use cortex_m_semihosting::hio;
|
||||
use cortex_m_semihosting::hprintln;
|
||||
|
||||
// this is the allocator the application will use
|
||||
#[global_allocator]
|
||||
@@ -39,8 +39,11 @@ fn main() -> ! {
|
||||
// Growable array allocated on the heap
|
||||
let xs = vec![0, 1, 2];
|
||||
|
||||
let mut stdout = hio::hstdout().unwrap();
|
||||
writeln!(stdout, "{:?}", xs).unwrap();
|
||||
hprintln!("{:?}", xs).unwrap();
|
||||
|
||||
// exit QEMU
|
||||
// NOTE do not run this on hardware; it can corrupt OpenOCD state
|
||||
debug::exit(debug::EXIT_SUCCESS);
|
||||
|
||||
loop {}
|
||||
}
|
||||
|
||||
@@ -27,11 +27,9 @@
|
||||
#[allow(unused_extern_crates)]
|
||||
extern crate panic_halt;
|
||||
|
||||
use core::fmt::Write;
|
||||
|
||||
use cortex_m::peripheral::syst::SystClkSource;
|
||||
use cortex_m_rt::entry;
|
||||
use cortex_m_semihosting::hio::{self, HStdout};
|
||||
use cortex_m_semihosting::hprint;
|
||||
use stm32f30x::{interrupt, Interrupt};
|
||||
|
||||
#[entry]
|
||||
@@ -53,19 +51,13 @@ fn main() -> ! {
|
||||
while !syst.has_wrapped() {}
|
||||
|
||||
// trigger the `EXTI0` interrupt
|
||||
nvic.set_pending(Interrupt::EXTI0);
|
||||
NVIC::pend(Interrupt::EXTI0);
|
||||
}
|
||||
}
|
||||
|
||||
// try commenting out this line: you'll end in `default_handler` instead of in `exti0`
|
||||
interrupt!(EXTI0, exti0, state: Option<HStdout> = None);
|
||||
interrupt!(EXTI0, exti0);
|
||||
|
||||
fn exti0(state: &mut Option<HStdout>) {
|
||||
if state.is_none() {
|
||||
*state = Some(hio::hstdout().unwrap());
|
||||
}
|
||||
|
||||
if let Some(hstdout) = state.as_mut() {
|
||||
hstdout.write_str(".").unwrap();
|
||||
}
|
||||
fn exti0() {
|
||||
hprint!(".").unwrap();
|
||||
}
|
||||
|
||||
@@ -12,12 +12,10 @@
|
||||
|
||||
extern crate panic_halt;
|
||||
|
||||
use core::fmt::Write;
|
||||
|
||||
use cortex_m::peripheral::syst::SystClkSource;
|
||||
use cortex_m::Peripherals;
|
||||
use cortex_m_rt::{entry, exception};
|
||||
use cortex_m_semihosting::hio::{self, HStdout};
|
||||
use cortex_m_semihosting::hprint;
|
||||
|
||||
#[entry]
|
||||
fn main() -> ! {
|
||||
@@ -35,13 +33,5 @@ fn main() -> ! {
|
||||
|
||||
#[exception]
|
||||
fn SysTick() {
|
||||
static mut STDOUT: Option<HStdout> = None;
|
||||
|
||||
if STDOUT.is_none() {
|
||||
*STDOUT = Some(hio::hstdout().unwrap());
|
||||
}
|
||||
|
||||
if let Some(hstdout) = STDOUT.as_mut() {
|
||||
hstdout.write_str(".").unwrap();
|
||||
}
|
||||
hprint!(".").unwrap();
|
||||
}
|
||||
|
||||
@@ -5,17 +5,15 @@
|
||||
|
||||
extern crate panic_halt;
|
||||
|
||||
use core::fmt::Write;
|
||||
|
||||
use cortex_m_rt::entry;
|
||||
use cortex_m_semihosting::{debug, hio};
|
||||
use cortex_m_semihosting::{debug, hprintln};
|
||||
|
||||
#[entry]
|
||||
fn main() -> ! {
|
||||
let mut stdout = hio::hstdout().unwrap();
|
||||
writeln!(stdout, "Hello, world!").unwrap();
|
||||
hprintln!("Hello, world!").unwrap();
|
||||
|
||||
// exit QEMU or the debugger section
|
||||
// exit QEMU
|
||||
// NOTE do not run this on hardware; it can corrupt OpenOCD state
|
||||
debug::exit(debug::EXIT_SUCCESS);
|
||||
|
||||
loop {}
|
||||
|
||||
Reference in New Issue
Block a user