mirror of
https://github.com/laanwj/k210-sdk-stuff.git
synced 2024-11-22 01:16:20 +04:00
rust/k210-shared: More helpful panic handler
Try sending the panic message to UARTHS.
This commit is contained in:
parent
b6676ffcf8
commit
1b48da7be0
@ -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"
|
||||
|
@ -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;
|
||||
|
@ -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"
|
||||
|
@ -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;
|
||||
|
@ -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"
|
||||
|
@ -4,8 +4,6 @@
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
|
||||
extern crate panic_halt;
|
||||
|
||||
mod console;
|
||||
mod cp437;
|
||||
mod cp437_8x8;
|
||||
|
@ -4,5 +4,6 @@
|
||||
#![no_std]
|
||||
|
||||
pub mod board;
|
||||
pub mod panic;
|
||||
pub mod soc;
|
||||
mod util;
|
||||
|
25
rust/k210-shared/src/panic.rs
Normal file
25
rust/k210-shared/src/panic.rs
Normal 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)
|
||||
}
|
||||
}
|
@ -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"
|
||||
|
@ -4,8 +4,6 @@
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
|
||||
extern crate panic_halt;
|
||||
|
||||
mod palette;
|
||||
|
||||
use k210_hal::pac;
|
||||
|
Loading…
Reference in New Issue
Block a user