rust/k210-shared: More helpful panic handler

Try sending the panic message to UARTHS.
This commit is contained in:
Wladimir J. van der Laan 2019-05-15 08:11:26 +00:00
parent b6676ffcf8
commit 1b48da7be0
10 changed files with 26 additions and 12 deletions

View File

@ -5,7 +5,6 @@ authors = ["W.J. van der Laan <laanwj@protonmail.com>"]
edition = "2018"
[dependencies]
panic-halt = "0.2.0"
riscv-rt = "0.5.0"
k210-hal = "0.1.0"
riscv = "0.5"

View File

@ -4,8 +4,6 @@
#![no_std]
#![no_main]
extern crate panic_halt;
use k210_hal::pac;
use k210_hal::prelude::*;
use k210_hal::stdout::Stdout;

View File

@ -5,7 +5,6 @@ authors = ["W.J. van der Laan <laanwj@protonmail.com>"]
edition = "2018"
[dependencies]
panic-halt = "0.2.0"
riscv-rt = "0.5.0"
k210-hal = "0.1.0"
riscv = "0.5"

View File

@ -4,8 +4,6 @@
#![no_std]
#![no_main]
extern crate panic_halt;
use k210_hal::pac;
use k210_hal::prelude::*;
use k210_hal::stdout::Stdout;

View File

@ -5,7 +5,6 @@ authors = ["W.J. van der Laan <laanwj@protonmail.com>"]
edition = "2018"
[dependencies]
panic-halt = "0.2.0"
riscv-rt = "0.5.0"
k210-hal = "0.1.0"
riscv = "0.5"

View File

@ -4,8 +4,6 @@
#![no_std]
#![no_main]
extern crate panic_halt;
mod console;
mod cp437;
mod cp437_8x8;

View File

@ -4,5 +4,6 @@
#![no_std]
pub mod board;
pub mod panic;
pub mod soc;
mod util;

View File

@ -0,0 +1,25 @@
/** Panic handler: based on ARM panic-itm */
use k210_hal::pac;
use k210_hal::prelude::*;
use k210_hal::stdout::Stdout;
use core::panic::PanicInfo;
use core::sync::atomic::{self, Ordering};
/** Send panic messages to UARTHS at 115200 baud */
#[panic_handler]
fn panic(info: &PanicInfo) -> ! {
// Stealing all peripherals, re-initializing the clocks and serial seems overkill here, but
// also, can we really know the state?
let p = unsafe { pac::Peripherals::steal() };
let clocks = k210_hal::clock::Clocks::new();
let serial = p.UARTHS.constrain(115_200.bps(), &clocks);
let (mut tx, _) = serial.split();
let mut stdout = Stdout(&mut tx);
writeln!(stdout, "{}", info).unwrap();
loop {
// add some side effect to prevent this from turning into a UDF instruction
// see rust-lang/rust#28728 for details
atomic::compiler_fence(Ordering::SeqCst)
}
}

View File

@ -5,7 +5,6 @@ authors = ["W.J. van der Laan <laanwj@protonmail.com>"]
edition = "2018"
[dependencies]
panic-halt = "0.2.0"
riscv-rt = "0.5.0"
k210-hal = "0.1.0"
riscv = "0.5"

View File

@ -4,8 +4,6 @@
#![no_std]
#![no_main]
extern crate panic_halt;
mod palette;
use k210_hal::pac;