diff options
Diffstat (limited to 'panic-semihosting')
-rw-r--r-- | panic-semihosting/CHANGELOG.md | 66 | ||||
-rw-r--r-- | panic-semihosting/Cargo.toml | 22 | ||||
-rw-r--r-- | panic-semihosting/README.md | 37 | ||||
-rw-r--r-- | panic-semihosting/src/lib.rs | 96 |
4 files changed, 221 insertions, 0 deletions
diff --git a/panic-semihosting/CHANGELOG.md b/panic-semihosting/CHANGELOG.md new file mode 100644 index 0000000..0036754 --- /dev/null +++ b/panic-semihosting/CHANGELOG.md @@ -0,0 +1,66 @@ +# Change Log + +All notable changes to this project will be documented in this file. + +The format is based on [Keep a Changelog](http://keepachangelog.com/) +and this project adheres to [Semantic Versioning](http://semver.org/). + +## [Unreleased] + +## [v0.5.3] - 2019-09-01 + +- Added feature `jlink-quirks` to work with JLink + +## [v0.5.2] - 2019-04-28 + +- Updated `cortex-m` version to not have the issue when linking multiple + versions of it. + +## [v0.5.1] - 2018-10-27 + +### Added + +- An opt-in "exit" Cargo feature to have the panic handler perform an exit + semihosting call after logging the panic message. + +## [v0.5.0] - 2018-09-10 + +- [breaking-change] The `panic_handler` feature gate has been removed. This + crate will compile on 1.30-beta and on stable 1.30 when they are released. + +## [v0.4.0] - 2018-09-03 + +### Changed + +- This crate no longer depends on `arm-none-eabi-gcc`. + +- [breaking-change] Move from the `panic_implementation` attribute to the + `panic_handler` attribute, which will be stabilized. + +## [v0.3.0] - 2018-06-04 + +### Changed + +- [breaking-change] moved from the, now removed, `panic_fmt` lang item to the + `#[panic_implementation]` attribute. + +## [v0.2.0] - 2018-05-11 + +### Changed + +- [breaking-change] made inline assembly (`asm!`) opt-in via the `"inline-asm"` feature. This is a + breaking change because this crate now requires `arm-none-eabi-gcc` to be installed to build + without the `"inline-asm"` feature, which is the default. + +## v0.1.0 - 2018-04-09 + +Initial release + +[Unreleased]: https://github.com/rust-embedded/panic-semihosting/compare/v0.5.3...HEAD +[v0.5.3]: https://github.com/rust-embedded/panic-semihosting/compare/v0.5.2...v0.5.3 +[v0.5.2]: https://github.com/rust-embedded/panic-semihosting/compare/v0.5.1...v0.5.2 +[v0.5.1]: https://github.com/rust-embedded/panic-semihosting/compare/v0.5.0...v0.5.1 +[v0.5.0]: https://github.com/rust-embedded/panic-semihosting/compare/v0.4.0...v0.5.0 +[v0.4.0]: https://github.com/rust-embedded/panic-semihosting/compare/v0.3.0...v0.4.0 +[v0.3.0]: https://github.com/rust-embedded/panic-semihosting/compare/v0.2.0...v0.3.0 +[v0.2.0]: https://github.com/rust-embedded/panic-semihosting/compare/v0.1.0...v0.2.0 diff --git a/panic-semihosting/Cargo.toml b/panic-semihosting/Cargo.toml new file mode 100644 index 0000000..2e6c3be --- /dev/null +++ b/panic-semihosting/Cargo.toml @@ -0,0 +1,22 @@ +[package] +authors = [ + "The Cortex-M Team <cortex-m@teams.rust-embedded.org>", + "Jorge Aparicio <jorge@japaric.io>", +] +categories = ["no-std"] +description = "Report panic messages to the host stderr using semihosting" +documentation = "https://docs.rs/panic-semihosting" +keywords = ["panic-handler", "panic-impl", "panic", "semihosting"] +license = "MIT OR Apache-2.0" +name = "panic-semihosting" +repository = "https://github.com/rust-embedded/cortex-m" +version = "0.5.3" + +[dependencies] +cortex-m = { path = "..", version = ">= 0.5.6, < 0.7" } +cortex-m-semihosting = { path = "../cortex-m-semihosting", version = "0.3" } + +[features] +exit = [] +inline-asm = ["cortex-m-semihosting/inline-asm", "cortex-m/inline-asm"] +jlink-quirks = ["cortex-m-semihosting/jlink-quirks"] diff --git a/panic-semihosting/README.md b/panic-semihosting/README.md new file mode 100644 index 0000000..baacf1a --- /dev/null +++ b/panic-semihosting/README.md @@ -0,0 +1,37 @@ +# `panic-semihosting` + +> Report panic messages to the host stderr using semihosting + +This project is developed and maintained by the [Cortex-M team][team]. + +## [Documentation](https://docs.rs/panic-semihosting) + +## Minimum Supported Rust Version (MSRV) + +This crate is guaranteed to compile on stable Rust 1.32.0 and up. It *might* +compile with older versions but that may change in any new patch release. + +## License + +Licensed under either of + +- Apache License, Version 2.0 ([LICENSE-APACHE](../LICENSE-APACHE) or + http://www.apache.org/licenses/LICENSE-2.0) +- MIT license ([LICENSE-MIT](../LICENSE-MIT) or http://opensource.org/licenses/MIT) + +at your option. + +### Contribution + +Unless you explicitly state otherwise, any contribution intentionally submitted +for inclusion in the work by you, as defined in the Apache-2.0 license, shall be +dual licensed as above, without any additional terms or conditions. + +## Code of Conduct + +Contribution to this crate is organized under the terms of the [Rust Code of +Conduct][CoC], the maintainer of this crate, the [Cortex-M team][team], promises +to intervene to uphold that code of conduct. + +[CoC]: ../CODE_OF_CONDUCT.md +[team]: https://github.com/rust-embedded/wg#the-cortex-m-team diff --git a/panic-semihosting/src/lib.rs b/panic-semihosting/src/lib.rs new file mode 100644 index 0000000..1db7b72 --- /dev/null +++ b/panic-semihosting/src/lib.rs @@ -0,0 +1,96 @@ +//! Report panic messages to the host stderr using semihosting +//! +//! This crate contains an implementation of `panic_fmt` that logs panic messages to the host stderr +//! using [`cortex-m-semihosting`]. Before logging the message the panic handler disables (masks) +//! the device specific interrupts. After logging the message the panic handler trigger a breakpoint +//! and then goes into an infinite loop. +//! +//! Currently, this crate only supports the ARM Cortex-M architecture. +//! +//! [`cortex-m-semihosting`]: https://crates.io/crates/cortex-m-semihosting +//! +//! # Usage +//! +//! ``` ignore +//! #![no_std] +//! +//! extern crate panic_semihosting; +//! +//! fn main() { +//! panic!("FOO") +//! } +//! ``` +//! +//! ``` text +//! (gdb) monitor arm semihosting enable +//! (gdb) continue +//! Program received signal SIGTRAP, Trace/breakpoint trap. +//! rust_begin_unwind (args=..., file=..., line=8, col=5) +//! at $CRATE/src/lib.rs:69 +//! 69 asm::bkpt(); +//! ``` +//! +//! ``` text +//! $ openocd -f (..) +//! (..) +//! panicked at 'FOO', src/main.rs:6:5 +//! ``` +//! +//! # Optional features +//! +//! ## `exit` +//! +//! When this feature is enabled the panic handler performs an exit semihosting call after logging +//! the panic message. This is useful when emulating the program on QEMU as it causes the QEMU +//! process to exit with a non-zero exit code; thus it can be used to implement Cortex-M tests that +//! run on the host. +//! +//! We discourage using this feature when the program will run on hardware as the exit call can +//! leave the hardware debugger in an inconsistent state. +//! +//! ## `inline-asm` +//! +//! When this feature is enabled semihosting is implemented using inline assembly (`asm!`) and +//! compiling this crate requires nightly. +//! +//! When this feature is disabled semihosting is implemented using FFI calls into an external +//! assembly file and compiling this crate works on stable and beta. + +#![cfg(all(target_arch = "arm", target_os = "none"))] +#![deny(missing_docs)] +#![deny(warnings)] +#![no_std] + +extern crate cortex_m; +extern crate cortex_m_semihosting as sh; + +use core::fmt::Write; +use core::panic::PanicInfo; + +#[cfg(not(feature = "exit"))] +use cortex_m::asm; +use cortex_m::interrupt; +#[cfg(feature = "exit")] +use sh::debug::{self, EXIT_FAILURE}; +use sh::hio; + +#[panic_handler] +fn panic(info: &PanicInfo) -> ! { + interrupt::disable(); + + if let Ok(mut hstdout) = hio::hstdout() { + writeln!(hstdout, "{}", info).ok(); + } + + match () { + // Exit the QEMU process + #[cfg(feature = "exit")] + () => debug::exit(EXIT_FAILURE), + // OK to fire a breakpoint here because we know the microcontroller is connected to a + // debugger + #[cfg(not(feature = "exit"))] + () => asm::bkpt(), + } + + loop {} +} |