Skip to content

Import panic-itm #291

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Nov 14, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down
1 change: 1 addition & 0 deletions cortex-m-semihosting/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
54 changes: 54 additions & 0 deletions panic-itm/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
16 changes: 16 additions & 0 deletions panic-itm/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[package]
authors = [
"The Cortex-M Team <[email protected]>",
"Jorge Aparicio <[email protected]>",
]
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" }
37 changes: 37 additions & 0 deletions panic-itm/README.md
Original file line number Diff line number Diff line change
@@ -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
59 changes: 59 additions & 0 deletions panic-itm/src/lib.rs
Original file line number Diff line number Diff line change
@@ -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);
}
}
2 changes: 1 addition & 1 deletion panic-semihosting/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ authors = [
"The Cortex-M Team <[email protected]>",
"Jorge Aparicio <[email protected]>",
]
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"]
Expand Down
50 changes: 30 additions & 20 deletions xtask/tests/ci.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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");
Expand All @@ -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, &[]);

Expand Down Expand Up @@ -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();
Expand Down