Skip to content

Commit a81bb98

Browse files
committed
default panic! to abort, drop panic-* features, add panic_fmt! macro
1 parent a2af5e2 commit a81bb98

File tree

3 files changed

+14
-36
lines changed

3 files changed

+14
-36
lines changed

cortex-m-rt/Cargo.toml

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,9 @@ r0 = "0.2.1"
1616
optional = true
1717
version = "0.2.7"
1818

19-
[dependencies.cortex-m-semihosting]
20-
optional = true
21-
version = "0.1.3"
22-
2319
[features]
2420
default = ["exceptions", "linker-script"]
2521
# service all exceptions using the default handler
2622
exceptions = ["cortex-m"]
2723
# generic linker script
2824
linker-script = []
29-
# prints panic messages to the ITM
30-
panic-over-itm = ["cortex-m"]
31-
# prints panic messages to the host stdout
32-
panic-over-semihosting = ["cortex-m-semihosting"]

cortex-m-rt/src/lang_items.rs

Lines changed: 12 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -6,32 +6,21 @@ unsafe extern "C" fn panic_fmt(
66
_file: &'static str,
77
_line: u32,
88
) -> ! {
9-
match () {
10-
#[cfg(feature = "panic-over-itm")]
11-
() => {
12-
use cortex_m::itm;
13-
use cortex_m::peripheral::ITM;
9+
::core::intrinsics::abort()
10+
}
1411

15-
let port = &(*ITM.get()).stim[0];
16-
iprint!(port, "panicked at '");
17-
itm::write_fmt(port, _args);
18-
iprintln!(port, "', {}:{}", _file, _line);
19-
}
20-
#[cfg(feature = "panic-over-semihosting")]
21-
() => {
22-
hprint!("panicked at '");
23-
::cortex_m_semihosting::io::write_fmt(_args);
24-
hprintln!("', {}:{}", _file, _line);
12+
#[macro_export]
13+
macro_rules! panic_fmt {
14+
($f:expr) => {
15+
#[export_name = "rust_begin_unwind"]
16+
pub unsafe extern "C" fn _panic_fmt(
17+
args: ::core::fmt::Arguments,
18+
file: &'static str,
19+
line: u32,
20+
) -> ! {
21+
$f(args, file, line)
2522
}
26-
#[cfg(not(any(feature = "panic-over-itm",
27-
feature = "panic-over-semihosting")))]
28-
() => {}
2923
}
30-
31-
#[cfg(target_arch = "arm")]
32-
asm!("bkpt" :::: "volatile");
33-
34-
loop {}
3524
}
3625

3726
/// Lang item required to make the normal `main` work in applications

cortex-m-rt/src/lib.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -149,18 +149,15 @@
149149
#![deny(warnings)]
150150
#![feature(asm)]
151151
#![feature(compiler_builtins_lib)]
152+
#![feature(core_intrinsics)]
152153
#![feature(lang_items)]
153154
#![feature(linkage)]
154155
#![feature(used)]
155156
#![no_std]
156157

157-
#[cfg(any(feature = "panic-over-itm", feature = "exceptions"))]
158-
#[cfg_attr(feature = "panic-over-itm", macro_use)]
158+
#[cfg(feature = "exceptions")]
159159
extern crate cortex_m;
160160
extern crate compiler_builtins;
161-
#[cfg(feature = "panic-over-semihosting")]
162-
#[macro_use]
163-
extern crate cortex_m_semihosting;
164161
extern crate r0;
165162

166163
mod lang_items;

0 commit comments

Comments
 (0)