diff options
author | 2020-11-11 00:35:40 +0100 | |
---|---|---|
committer | 2020-11-11 00:35:40 +0100 | |
commit | 5b65e95f816dfc96a1921c8837127581215aafd6 (patch) | |
tree | b45e99d9f8e7368b6920afab5b5420e4c49feed5 | |
parent | bc8c562cf110d64d20461ff19052559fba5e500b (diff) | |
download | cortex-m-5b65e95f816dfc96a1921c8837127581215aafd6.tar.gz cortex-m-5b65e95f816dfc96a1921c8837127581215aafd6.tar.zst cortex-m-5b65e95f816dfc96a1921c8837127581215aafd6.zip |
Import panic-itm
-rw-r--r-- | Cargo.toml | 2 | ||||
-rw-r--r-- | panic-itm/CHANGELOG.md | 54 | ||||
-rw-r--r-- | panic-itm/Cargo.toml | 16 | ||||
-rw-r--r-- | panic-itm/README.md | 37 | ||||
-rw-r--r-- | panic-itm/src/lib.rs | 58 | ||||
-rw-r--r-- | xtask/tests/ci.rs | 50 |
6 files changed, 196 insertions, 21 deletions
@@ -27,7 +27,7 @@ inline-asm = [] linker-plugin-lto = [] [workspace] -members = ["xtask", "cortex-m-semihosting", "panic-semihosting"] +members = ["xtask", "cortex-m-semihosting", "panic-semihosting", "panic-itm"] [package.metadata.docs.rs] targets = [ diff --git a/panic-itm/CHANGELOG.md b/panic-itm/CHANGELOG.md new file mode 100644 index 0000000..552b5f6 --- /dev/null +++ b/panic-itm/CHANGELOG.md @@ -0,0 +1,54 @@ +# 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.4.1] - 2019-04-28 + +- Updated `cortex-m` version to not have the issue when linking multiple + versions of it. + +## [v0.4.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.3.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.2.0] - 2018-06-04 + +### Changed + +- [breaking-change] moved from the, now removed, `panic_fmt` lang item to the + `#[panic_implementation]` attribute. + +## [v0.1.1] - 2018-05-11 + +### Changed + +- Specify the full behavior of the panic handler in the documentation. + +- Remove the unspecified behavior of aborting after printing the message. This lets us drop the + `core_intrinsics` feature gate. + +## v0.1.0 - 2018-04-09 + +Initial release + +[Unreleased]: https://github.com/japaric/panic-itm/compare/v0.4.1...HEAD +[v0.4.1]: https://github.com/japaric/panic-itm/compare/v0.4.0...v0.4.1 +[v0.4.0]: https://github.com/japaric/panic-itm/compare/v0.3.0...v0.4.0 +[v0.3.0]: https://github.com/japaric/panic-itm/compare/v0.2.0...v0.3.0 +[v0.2.0]: https://github.com/japaric/panic-itm/compare/v0.1.1...v0.2.0 +[v0.1.1]: https://github.com/japaric/panic-itm/compare/v0.1.0...v0.1.1 diff --git a/panic-itm/Cargo.toml b/panic-itm/Cargo.toml new file mode 100644 index 0000000..e42d45a --- /dev/null +++ b/panic-itm/Cargo.toml @@ -0,0 +1,16 @@ +[package] +authors = [ + "The Cortex-M Team <cortex-m@teams.rust-embedded.org>", + "Jorge Aparicio <jorge@japaric.io>", +] +categories = ["no-std"] +description = "Log panic messages using the ITM (Instrumentation Trace Macrocell)" +documentation = "https://rust-embedded.github.io/panic-itm/panic_itm" +keywords = ["panic-impl", "panic-handler", "ITM", "ARM", "Cortex-M"] +license = "MIT OR Apache-2.0" +name = "panic-itm" +repository = "https://github.com/rust-embedded/panic-itm" +version = "0.4.1" + +[dependencies] +cortex-m = { path = "..", version = ">= 0.5.8, < 0.8" } diff --git a/panic-itm/README.md b/panic-itm/README.md new file mode 100644 index 0000000..38a4d46 --- /dev/null +++ b/panic-itm/README.md @@ -0,0 +1,37 @@ +# `panic-itm` + +> Log panic messages using the ITM (Instrumentation Trace Macrocell) + +This project is developed and maintained by the [Cortex-M team][team]. + +## [Documentation](https://docs.rs/panic-itm) + +## Minimum Supported Rust Version (MSRV) + +This crate is guaranteed to compile on stable Rust 1.31.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-itm/src/lib.rs b/panic-itm/src/lib.rs new file mode 100644 index 0000000..eedc38c --- /dev/null +++ b/panic-itm/src/lib.rs @@ -0,0 +1,58 @@ +//! Log panic messages using the ITM (Instrumentation Trace Macrocell) +//! +//! This crate contains an implementation of `panic_fmt` that logs panic messages to the ITM +//! stimulus port 0. Before printing the message the panic handler disables (masks) all the device +//! specific interrupts. After printing the message the panic handler goes into an infinite loop. +//! +//! # Usage +//! +//! ``` ignore +//! #![no_std] +//! +//! extern crate panic_itm; +//! +//! fn main() { +//! panic!("FOO") +//! } +//! ``` +//! +//! ``` text +//! (gdb) monitor tpiu config external uart off 8000000 2000000 +//! (gdb) monitor itm port 0 on +//! (gdb) continue +//! (..) +//! ``` +//! +//! ``` text +//! $ itmdump -f /dev/ttyUSB0 +//! panicked at 'FOO', src/main.rs:6:5 +//! ``` + +#![deny(missing_docs)] +#![deny(warnings)] +#![no_std] + +extern crate cortex_m; + +use core::panic::PanicInfo; +use core::sync::atomic::{self, Ordering}; + +use cortex_m::interrupt; +use cortex_m::iprintln; +use cortex_m::peripheral::ITM; + +#[panic_handler] +fn panic(info: &PanicInfo) -> ! { + interrupt::disable(); + + let itm = unsafe { &mut *ITM::ptr() }; + let stim = &mut itm.stim[0]; + + iprintln!(stim, "{}", info); + + 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); + } +} diff --git a/xtask/tests/ci.rs b/xtask/tests/ci.rs index 5b449ba..a261783 100644 --- a/xtask/tests/ci.rs +++ b/xtask/tests/ci.rs @@ -5,7 +5,7 @@ use xtask::{check_blobs, install_targets}; /// List of all compilation targets we support. /// /// This should generally list all of the bare-metal thumb targets starting at thumbv6. -static TARGETS: &[&str] = &[ +static ALL_TARGETS: &[&str] = &[ "thumbv6m-none-eabi", "thumbv7m-none-eabi", "thumbv7em-none-eabi", @@ -15,6 +15,15 @@ static TARGETS: &[&str] = &[ "thumbv8m.main-none-eabihf", ]; +/// Same as the list above, except with all "base" targets that have a reduced feature set removed. +static NON_BASE_TARGETS: &[&str] = &[ + "thumbv7m-none-eabi", + "thumbv7em-none-eabi", + "thumbv7em-none-eabihf", + "thumbv8m.main-none-eabi", + "thumbv8m.main-none-eabihf", +]; + fn build(package: &str, target: &str, features: &[&str]) { println!("building {} for {} {:?}", package, target, features); let mut cargo = Command::new("cargo"); @@ -34,29 +43,30 @@ fn build(package: &str, target: &str, features: &[&str]) { } #[rustfmt::skip] -static PACKAGE_FEATURES: &[(&str, &[&str])] = &[ - ("cortex-m", &["inline-asm", "cm7-r0p1"]), // no `linker-plugin-lto` since it's experimental - ("cortex-m-semihosting", &["inline-asm", "no-semihosting", "jlink-quirks"]), - ("panic-semihosting", &["inline-asm", "exit", "jlink-quirks"]), +static PACKAGE_FEATURES: &[(&str, &[&str], &[&str])] = &[ + ("cortex-m", ALL_TARGETS, &["inline-asm", "cm7-r0p1"]), // no `linker-plugin-lto` since it's experimental + ("cortex-m-semihosting", ALL_TARGETS, &["inline-asm", "no-semihosting", "jlink-quirks"]), + ("panic-semihosting", ALL_TARGETS, &["inline-asm", "exit", "jlink-quirks"]), + ("panic-itm", NON_BASE_TARGETS, &[]), ]; fn check_crates_build(is_nightly: bool) { // Build all crates for each supported target. - for &target in TARGETS { - // Filters crate features, keeping only those that are supported. - // Relies on all crates in this repo to use the same convention. - let should_use_feature = |feat: &str| { - match feat { - // This is nightly-only, so don't use it on stable. - "inline-asm" => is_nightly, - // This only affects thumbv7em targets. - "cm7-r0p1" => target.starts_with("thumbv7em"), - - _ => true, - } - }; + for (package, targets, all_features) in PACKAGE_FEATURES { + for target in *targets { + // Filters crate features, keeping only those that are supported. + // Relies on all crates in this repo to use the same convention. + let should_use_feature = |feat: &str| { + match feat { + // This is nightly-only, so don't use it on stable. + "inline-asm" => is_nightly, + // This only affects thumbv7em targets. + "cm7-r0p1" => target.starts_with("thumbv7em"), + + _ => true, + } + }; - for (package, all_features) in PACKAGE_FEATURES { // Every crate must build with the default feature set. build(package, target, &[]); @@ -86,7 +96,7 @@ fn main() { // Tests execute in the containing crate's root dir, `cd ..` so that we find `asm` etc. env::set_current_dir("..").unwrap(); - install_targets(&mut TARGETS.iter().cloned(), None); + install_targets(&mut ALL_TARGETS.iter().cloned(), None); // Check that the ASM blobs are up-to-date. check_blobs(); |