diff options
author | 2020-11-14 13:26:47 +0000 | |
---|---|---|
committer | 2020-11-14 13:26:47 +0000 | |
commit | d86baecedcba528e1081e006dbf0a29bd7038374 (patch) | |
tree | 4f7f86aa4c6df2ad7e2ab7beda8ab16889d7954f | |
parent | bc8c562cf110d64d20461ff19052559fba5e500b (diff) | |
parent | bedf19b799ec754ec65a06ef684820c1b0d3ae58 (diff) | |
download | cortex-m-d86baecedcba528e1081e006dbf0a29bd7038374.tar.gz cortex-m-d86baecedcba528e1081e006dbf0a29bd7038374.tar.zst cortex-m-d86baecedcba528e1081e006dbf0a29bd7038374.zip |
Merge #291p-i-v0.4.1
291: Import panic-itm r=adamgreig a=jonas-schievink
Co-authored-by: Jonas Schievink <jonasschievink@gmail.com>
-rw-r--r-- | Cargo.toml | 2 | ||||
-rw-r--r-- | cortex-m-semihosting/Cargo.toml | 1 | ||||
-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 | 59 | ||||
-rw-r--r-- | panic-semihosting/Cargo.toml | 2 | ||||
-rw-r--r-- | xtask/tests/ci.rs | 50 |
8 files changed, 199 insertions, 22 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/cortex-m-semihosting/Cargo.toml b/cortex-m-semihosting/Cargo.toml index c6204eb..5894029 100644 --- a/cortex-m-semihosting/Cargo.toml +++ b/cortex-m-semihosting/Cargo.toml @@ -6,6 +6,7 @@ authors = [ description = "Semihosting for ARM Cortex-M processors" documentation = "https://docs.rs/cortex-m-semihosting" keywords = ["semihosting", "arm", "cortex-m"] +categories = ["no-std", "embedded"] license = "MIT OR Apache-2.0" name = "cortex-m-semihosting" readme = "README.md" diff --git a/panic-itm/CHANGELOG.md b/panic-itm/CHANGELOG.md new file mode 100644 index 0000000..2d955cb --- /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/rust-embedded/panic-itm/compare/v0.4.1...HEAD +[v0.4.1]: https://github.com/rust-embedded/panic-itm/compare/v0.4.0...v0.4.1 +[v0.4.0]: https://github.com/rust-embedded/panic-itm/compare/v0.3.0...v0.4.0 +[v0.3.0]: https://github.com/rust-embedded/panic-itm/compare/v0.2.0...v0.3.0 +[v0.2.0]: https://github.com/rust-embedded/panic-itm/compare/v0.1.1...v0.2.0 +[v0.1.1]: https://github.com/rust-embedded/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..23cf1f3 --- /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", "embedded"] +description = "Log panic messages using the ITM (Instrumentation Trace Macrocell)" +documentation = "https://docs.rs/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/cortex-m" +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..d85ecb7 --- /dev/null +++ b/panic-itm/src/lib.rs @@ -0,0 +1,59 @@ +//! 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 +//! ``` + +#![cfg(all(target_arch = "arm", target_os = "none"))] +#![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/panic-semihosting/Cargo.toml b/panic-semihosting/Cargo.toml index cf0e978..d38b0cd 100644 --- a/panic-semihosting/Cargo.toml +++ b/panic-semihosting/Cargo.toml @@ -3,7 +3,7 @@ authors = [ "The Cortex-M Team <cortex-m@teams.rust-embedded.org>", "Jorge Aparicio <jorge@japaric.io>", ] -categories = ["no-std"] +categories = ["no-std", "embedded"] description = "Report panic messages to the host stderr using semihosting" documentation = "https://docs.rs/panic-semihosting" keywords = ["panic-handler", "panic-impl", "panic", "semihosting"] 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(); |