Skip to content

Commit d86baec

Browse files
Merge #291
291: Import panic-itm r=adamgreig a=jonas-schievink Co-authored-by: Jonas Schievink <[email protected]>
2 parents bc8c562 + bedf19b commit d86baec

File tree

8 files changed

+199
-22
lines changed

8 files changed

+199
-22
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ inline-asm = []
2727
linker-plugin-lto = []
2828

2929
[workspace]
30-
members = ["xtask", "cortex-m-semihosting", "panic-semihosting"]
30+
members = ["xtask", "cortex-m-semihosting", "panic-semihosting", "panic-itm"]
3131

3232
[package.metadata.docs.rs]
3333
targets = [

cortex-m-semihosting/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ authors = [
66
description = "Semihosting for ARM Cortex-M processors"
77
documentation = "https://docs.rs/cortex-m-semihosting"
88
keywords = ["semihosting", "arm", "cortex-m"]
9+
categories = ["no-std", "embedded"]
910
license = "MIT OR Apache-2.0"
1011
name = "cortex-m-semihosting"
1112
readme = "README.md"

panic-itm/CHANGELOG.md

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# Change Log
2+
3+
All notable changes to this project will be documented in this file.
4+
5+
The format is based on [Keep a Changelog](http://keepachangelog.com/)
6+
and this project adheres to [Semantic Versioning](http://semver.org/).
7+
8+
## [Unreleased]
9+
10+
## [v0.4.1] - 2019-04-28
11+
12+
- Updated `cortex-m` version to not have the issue when linking multiple
13+
versions of it.
14+
15+
## [v0.4.0] - 2018-09-10
16+
17+
- [breaking-change] The `panic_handler` feature gate has been removed. This
18+
crate will compile on 1.30-beta and on stable 1.30 when they are released.
19+
20+
## [v0.3.0] - 2018-09-03
21+
22+
### Changed
23+
24+
- This crate no longer depends on `arm-none-eabi-gcc`.
25+
26+
- [breaking-change] Move from the `panic_implementation` attribute to the
27+
`panic_handler` attribute, which will be stabilized.
28+
29+
## [v0.2.0] - 2018-06-04
30+
31+
### Changed
32+
33+
- [breaking-change] moved from the, now removed, `panic_fmt` lang item to the
34+
`#[panic_implementation]` attribute.
35+
36+
## [v0.1.1] - 2018-05-11
37+
38+
### Changed
39+
40+
- Specify the full behavior of the panic handler in the documentation.
41+
42+
- Remove the unspecified behavior of aborting after printing the message. This lets us drop the
43+
`core_intrinsics` feature gate.
44+
45+
## v0.1.0 - 2018-04-09
46+
47+
Initial release
48+
49+
[Unreleased]: https://github.com/rust-embedded/panic-itm/compare/v0.4.1...HEAD
50+
[v0.4.1]: https://github.com/rust-embedded/panic-itm/compare/v0.4.0...v0.4.1
51+
[v0.4.0]: https://github.com/rust-embedded/panic-itm/compare/v0.3.0...v0.4.0
52+
[v0.3.0]: https://github.com/rust-embedded/panic-itm/compare/v0.2.0...v0.3.0
53+
[v0.2.0]: https://github.com/rust-embedded/panic-itm/compare/v0.1.1...v0.2.0
54+
[v0.1.1]: https://github.com/rust-embedded/panic-itm/compare/v0.1.0...v0.1.1

panic-itm/Cargo.toml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
[package]
2+
authors = [
3+
"The Cortex-M Team <[email protected]>",
4+
"Jorge Aparicio <[email protected]>",
5+
]
6+
categories = ["no-std", "embedded"]
7+
description = "Log panic messages using the ITM (Instrumentation Trace Macrocell)"
8+
documentation = "https://docs.rs/panic-itm"
9+
keywords = ["panic-impl", "panic-handler", "ITM", "ARM", "Cortex-M"]
10+
license = "MIT OR Apache-2.0"
11+
name = "panic-itm"
12+
repository = "https://github.com/rust-embedded/cortex-m"
13+
version = "0.4.1"
14+
15+
[dependencies]
16+
cortex-m = { path = "..", version = ">= 0.5.8, < 0.8" }

panic-itm/README.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# `panic-itm`
2+
3+
> Log panic messages using the ITM (Instrumentation Trace Macrocell)
4+
5+
This project is developed and maintained by the [Cortex-M team][team].
6+
7+
## [Documentation](https://docs.rs/panic-itm)
8+
9+
## Minimum Supported Rust Version (MSRV)
10+
11+
This crate is guaranteed to compile on stable Rust 1.31.0 and up. It *might*
12+
compile with older versions but that may change in any new patch release.
13+
14+
## License
15+
16+
Licensed under either of
17+
18+
- Apache License, Version 2.0 ([LICENSE-APACHE](LICENSE-APACHE) or
19+
http://www.apache.org/licenses/LICENSE-2.0)
20+
- MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT)
21+
22+
at your option.
23+
24+
### Contribution
25+
26+
Unless you explicitly state otherwise, any contribution intentionally submitted
27+
for inclusion in the work by you, as defined in the Apache-2.0 license, shall be
28+
dual licensed as above, without any additional terms or conditions.
29+
30+
## Code of Conduct
31+
32+
Contribution to this crate is organized under the terms of the [Rust Code of
33+
Conduct][CoC], the maintainer of this crate, the [Cortex-M team][team], promises
34+
to intervene to uphold that code of conduct.
35+
36+
[CoC]: CODE_OF_CONDUCT.md
37+
[team]: https://github.com/rust-embedded/wg#the-cortex-m-team

panic-itm/src/lib.rs

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
//! Log panic messages using the ITM (Instrumentation Trace Macrocell)
2+
//!
3+
//! This crate contains an implementation of `panic_fmt` that logs panic messages to the ITM
4+
//! stimulus port 0. Before printing the message the panic handler disables (masks) all the device
5+
//! specific interrupts. After printing the message the panic handler goes into an infinite loop.
6+
//!
7+
//! # Usage
8+
//!
9+
//! ``` ignore
10+
//! #![no_std]
11+
//!
12+
//! extern crate panic_itm;
13+
//!
14+
//! fn main() {
15+
//! panic!("FOO")
16+
//! }
17+
//! ```
18+
//!
19+
//! ``` text
20+
//! (gdb) monitor tpiu config external uart off 8000000 2000000
21+
//! (gdb) monitor itm port 0 on
22+
//! (gdb) continue
23+
//! (..)
24+
//! ```
25+
//!
26+
//! ``` text
27+
//! $ itmdump -f /dev/ttyUSB0
28+
//! panicked at 'FOO', src/main.rs:6:5
29+
//! ```
30+
31+
#![cfg(all(target_arch = "arm", target_os = "none"))]
32+
#![deny(missing_docs)]
33+
#![deny(warnings)]
34+
#![no_std]
35+
36+
extern crate cortex_m;
37+
38+
use core::panic::PanicInfo;
39+
use core::sync::atomic::{self, Ordering};
40+
41+
use cortex_m::interrupt;
42+
use cortex_m::iprintln;
43+
use cortex_m::peripheral::ITM;
44+
45+
#[panic_handler]
46+
fn panic(info: &PanicInfo) -> ! {
47+
interrupt::disable();
48+
49+
let itm = unsafe { &mut *ITM::ptr() };
50+
let stim = &mut itm.stim[0];
51+
52+
iprintln!(stim, "{}", info);
53+
54+
loop {
55+
// add some side effect to prevent this from turning into a UDF instruction
56+
// see rust-lang/rust#28728 for details
57+
atomic::compiler_fence(Ordering::SeqCst);
58+
}
59+
}

panic-semihosting/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ authors = [
33
"The Cortex-M Team <[email protected]>",
44
"Jorge Aparicio <[email protected]>",
55
]
6-
categories = ["no-std"]
6+
categories = ["no-std", "embedded"]
77
description = "Report panic messages to the host stderr using semihosting"
88
documentation = "https://docs.rs/panic-semihosting"
99
keywords = ["panic-handler", "panic-impl", "panic", "semihosting"]

xtask/tests/ci.rs

Lines changed: 30 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use xtask::{check_blobs, install_targets};
55
/// List of all compilation targets we support.
66
///
77
/// This should generally list all of the bare-metal thumb targets starting at thumbv6.
8-
static TARGETS: &[&str] = &[
8+
static ALL_TARGETS: &[&str] = &[
99
"thumbv6m-none-eabi",
1010
"thumbv7m-none-eabi",
1111
"thumbv7em-none-eabi",
@@ -15,6 +15,15 @@ static TARGETS: &[&str] = &[
1515
"thumbv8m.main-none-eabihf",
1616
];
1717

18+
/// Same as the list above, except with all "base" targets that have a reduced feature set removed.
19+
static NON_BASE_TARGETS: &[&str] = &[
20+
"thumbv7m-none-eabi",
21+
"thumbv7em-none-eabi",
22+
"thumbv7em-none-eabihf",
23+
"thumbv8m.main-none-eabi",
24+
"thumbv8m.main-none-eabihf",
25+
];
26+
1827
fn build(package: &str, target: &str, features: &[&str]) {
1928
println!("building {} for {} {:?}", package, target, features);
2029
let mut cargo = Command::new("cargo");
@@ -34,29 +43,30 @@ fn build(package: &str, target: &str, features: &[&str]) {
3443
}
3544

3645
#[rustfmt::skip]
37-
static PACKAGE_FEATURES: &[(&str, &[&str])] = &[
38-
("cortex-m", &["inline-asm", "cm7-r0p1"]), // no `linker-plugin-lto` since it's experimental
39-
("cortex-m-semihosting", &["inline-asm", "no-semihosting", "jlink-quirks"]),
40-
("panic-semihosting", &["inline-asm", "exit", "jlink-quirks"]),
46+
static PACKAGE_FEATURES: &[(&str, &[&str], &[&str])] = &[
47+
("cortex-m", ALL_TARGETS, &["inline-asm", "cm7-r0p1"]), // no `linker-plugin-lto` since it's experimental
48+
("cortex-m-semihosting", ALL_TARGETS, &["inline-asm", "no-semihosting", "jlink-quirks"]),
49+
("panic-semihosting", ALL_TARGETS, &["inline-asm", "exit", "jlink-quirks"]),
50+
("panic-itm", NON_BASE_TARGETS, &[]),
4151
];
4252

4353
fn check_crates_build(is_nightly: bool) {
4454
// Build all crates for each supported target.
45-
for &target in TARGETS {
46-
// Filters crate features, keeping only those that are supported.
47-
// Relies on all crates in this repo to use the same convention.
48-
let should_use_feature = |feat: &str| {
49-
match feat {
50-
// This is nightly-only, so don't use it on stable.
51-
"inline-asm" => is_nightly,
52-
// This only affects thumbv7em targets.
53-
"cm7-r0p1" => target.starts_with("thumbv7em"),
54-
55-
_ => true,
56-
}
57-
};
55+
for (package, targets, all_features) in PACKAGE_FEATURES {
56+
for target in *targets {
57+
// Filters crate features, keeping only those that are supported.
58+
// Relies on all crates in this repo to use the same convention.
59+
let should_use_feature = |feat: &str| {
60+
match feat {
61+
// This is nightly-only, so don't use it on stable.
62+
"inline-asm" => is_nightly,
63+
// This only affects thumbv7em targets.
64+
"cm7-r0p1" => target.starts_with("thumbv7em"),
65+
66+
_ => true,
67+
}
68+
};
5869

59-
for (package, all_features) in PACKAGE_FEATURES {
6070
// Every crate must build with the default feature set.
6171
build(package, target, &[]);
6272

@@ -86,7 +96,7 @@ fn main() {
8696
// Tests execute in the containing crate's root dir, `cd ..` so that we find `asm` etc.
8797
env::set_current_dir("..").unwrap();
8898

89-
install_targets(&mut TARGETS.iter().cloned(), None);
99+
install_targets(&mut ALL_TARGETS.iter().cloned(), None);
90100

91101
// Check that the ASM blobs are up-to-date.
92102
check_blobs();

0 commit comments

Comments
 (0)