v0.2.0
This commit is contained in:
@@ -1,35 +1,58 @@
|
||||
//! Redirecting `panic!` messages
|
||||
//! Defining the panic handler
|
||||
//!
|
||||
//! The `cortex-m-rt` crate provides two options to redirect `panic!` messages
|
||||
//! through these two Cargo features:
|
||||
//! The panic handler can be defined through the `panic_fmt` [language item][1].
|
||||
//! Make sure that the "abort-on-panic" feature of the cortex-m-rt crate is
|
||||
//! disabled to avoid redefining the language item.
|
||||
//!
|
||||
//! - `panic-over-semihosting`. `panic!` messages will be printed to the OpenOCD
|
||||
//! console using semihosting. This is slow.
|
||||
//! [1]: https://doc.rust-lang.org/unstable-book/language-features/lang-items.html
|
||||
//!
|
||||
//! - `panic-over-itm`. `panic!` messages will be send through the ITM port 0.
|
||||
//! This is much faster but requires ITM support on the device.
|
||||
//!
|
||||
//! If neither of these options is specified then the `panic!` message will be
|
||||
//! lost. Note that all `panic!`s will trigger a debugger breakpoint.
|
||||
//! ---
|
||||
//!
|
||||
//! ```
|
||||
//!
|
||||
//! #![feature(core_intrinsics)]
|
||||
//! #![feature(lang_items)]
|
||||
//! #![feature(used)]
|
||||
//! #![no_std]
|
||||
//!
|
||||
//! extern crate cortex_m;
|
||||
//! extern crate cortex_m_rt;
|
||||
//! extern crate cortex_m_semihosting;
|
||||
//!
|
||||
//! use core::fmt::Write;
|
||||
//! use core::intrinsics;
|
||||
//!
|
||||
//! use cortex_m::asm;
|
||||
//! use cortex_m_semihosting::hio;
|
||||
//!
|
||||
//! fn main() {
|
||||
//! panic!("Oops");
|
||||
//! }
|
||||
//!
|
||||
//! #[lang = "panic_fmt"]
|
||||
//! #[no_mangle]
|
||||
//! unsafe extern "C" fn rust_begin_unwind(
|
||||
//! args: core::fmt::Arguments,
|
||||
//! file: &'static str,
|
||||
//! line: u32,
|
||||
//! col: u32,
|
||||
//! ) -> ! {
|
||||
//! if let Ok(mut stdout) = hio::hstdout() {
|
||||
//! write!(stdout, "panicked at '")
|
||||
//! .and_then(|_| {
|
||||
//! stdout
|
||||
//! .write_fmt(args)
|
||||
//! .and_then(|_| writeln!(stdout, "', {}:{}", file, line))
|
||||
//! })
|
||||
//! .ok();
|
||||
//! }
|
||||
//!
|
||||
//! intrinsics::abort()
|
||||
//! }
|
||||
//!
|
||||
//! // As we are not using interrupts, we just register a dummy catch all handler
|
||||
//! #[allow(dead_code)]
|
||||
//! #[link_section = ".vector_table.interrupts"]
|
||||
//! #[used]
|
||||
//! #[link_section = ".rodata.interrupts"]
|
||||
//! static INTERRUPTS: [extern "C" fn(); 240] = [default_handler; 240];
|
||||
//!
|
||||
//! extern "C" fn default_handler() {
|
||||
|
||||
Reference in New Issue
Block a user