panic_dcc/lib.rs
1//! Report panic messages to the host using the Debug Communication Channel (DCC)
2//!
3//! # Example
4//!
5//! ## Device side
6//!
7//! ``` ignore
8//! use panic_dcc;
9//!
10//! fn main() {
11//! panic!("Oops");
12//! }
13//! ```
14//!
15//! ## Host side
16//!
17//! ``` text
18//! $ # XSDB = Xilinx System Debugger
19//! $ xsdb
20//!
21//! (xsdb) # connect
22//! (xsdb) conn
23//!
24//! (xsdb) # select a Cortex-R core
25//! (xsdb) targets -set 0
26//!
27//! (xsdb) # hold the processor in reset state
28//! (xsdb) rst -processor
29//!
30//! (xsdb) # load program
31//! (xsdb) dow hello.elf
32//!
33//! (xsdb) # open a file
34//! (xsdb) set f [open dcc.log w]
35//!
36//! (xsdb) # redirect DCC output to file handle `f`
37//! (xsdb) readjtaguart -start -handle $f
38//!
39//! (xsdb) # start program execution
40//! (xsdb) con
41//! ```
42//!
43//! ``` text
44//! $ # on another terminal
45//! $ tail -f dcc.log
46//! panicked at 'Oops', src/hello.rs:4:4
47//! ```
48//!
49//! # Supported Rust version
50//!
51//! - Rust >=1.59
52
53#![deny(missing_docs)]
54#![deny(warnings)]
55#![no_std]
56
57#[cfg(not(debug_assertions))]
58use core::sync::atomic::{self, Ordering};
59use core::{fmt::Write, panic::PanicInfo};
60
61use arm_dcc::Writer;
62
63#[panic_handler]
64fn panic(info: &PanicInfo) -> ! {
65 // TODO uncomment
66 // cortex_r::disable_fiq();
67 // cortex_r::disable_irq();
68
69 // NOTE this operation never returns `Err`
70 writeln!(Writer, "{}", info).ok();
71
72 loop {
73 core::hint::spin_loop();
74 }
75}