Skip to content

Commit

Permalink
Improve CP0-disabled error message (#2061)
Browse files Browse the repository at this point in the history
* Improve CP0-disabled error message

* CHANGELOG.md
  • Loading branch information
bjoernQ authored Sep 2, 2024
1 parent b620e35 commit d60bafb
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
1 change: 1 addition & 0 deletions esp-backtrace/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added

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

### Fixed

Expand Down
2 changes: 1 addition & 1 deletion esp-backtrace/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ unsafe fn __user_exception(cause: arch::ExceptionCause, context: arch::Context)

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

#[cfg(feature = "defmt")]
defmt::error!("\n\nException occurred '{}'", cause);
Expand Down
14 changes: 12 additions & 2 deletions esp-backtrace/src/xtensa.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use core::arch::asm;
use core::{arch::asm, fmt::Display};

use crate::MAX_BACKTRACE_ADDRESSES;

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

/// Exception Cause
#[doc(hidden)]
#[derive(Debug, Clone, Copy)]
#[derive(Debug, Clone, Copy, PartialEq)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
#[repr(C)]
pub enum ExceptionCause {
Expand Down Expand Up @@ -99,6 +99,16 @@ pub enum ExceptionCause {
None = 255,
}

impl Display for ExceptionCause {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
if *self == Self::Cp0Disabled {
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.)")
} else {
write!(f, "{:?}", self)
}
}
}

#[doc(hidden)]
#[allow(non_snake_case)]
#[derive(Clone, Copy)]
Expand Down

0 comments on commit d60bafb

Please sign in to comment.