Skip to content

Commit d60bafb

Browse files
authored
Improve CP0-disabled error message (#2061)
* Improve CP0-disabled error message * CHANGELOG.md
1 parent b620e35 commit d60bafb

File tree

3 files changed

+14
-3
lines changed

3 files changed

+14
-3
lines changed

esp-backtrace/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1010
### Added
1111

1212
### Changed
13+
- Print a more helpful message in case of a `Cp0Disabled` exception (#2061)
1314

1415
### Fixed
1516

esp-backtrace/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ unsafe fn __user_exception(cause: arch::ExceptionCause, context: arch::Context)
100100

101101
// Unfortunately, a different formatter string is used
102102
#[cfg(not(feature = "defmt"))]
103-
esp_println::println!("\n\nException occurred '{:?}'", cause);
103+
esp_println::println!("\n\nException occurred '{}'", cause);
104104

105105
#[cfg(feature = "defmt")]
106106
defmt::error!("\n\nException occurred '{}'", cause);

esp-backtrace/src/xtensa.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use core::arch::asm;
1+
use core::{arch::asm, fmt::Display};
22

33
use crate::MAX_BACKTRACE_ADDRESSES;
44

@@ -11,7 +11,7 @@ pub(super) const RA_OFFSET: usize = 3;
1111

1212
/// Exception Cause
1313
#[doc(hidden)]
14-
#[derive(Debug, Clone, Copy)]
14+
#[derive(Debug, Clone, Copy, PartialEq)]
1515
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
1616
#[repr(C)]
1717
pub enum ExceptionCause {
@@ -99,6 +99,16 @@ pub enum ExceptionCause {
9999
None = 255,
100100
}
101101

102+
impl Display for ExceptionCause {
103+
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
104+
if *self == Self::Cp0Disabled {
105+
write!(f, "Cp0Disabled (Access to the floating point coprocessor is not allowed. You may want to enable the `float-save-restore` feature of the `xtensa-lx-rt` crate.)")
106+
} else {
107+
write!(f, "{:?}", self)
108+
}
109+
}
110+
}
111+
102112
#[doc(hidden)]
103113
#[allow(non_snake_case)]
104114
#[derive(Clone, Copy)]

0 commit comments

Comments
 (0)