Skip to content
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

Improve CP0-disabled error message #2061

Merged
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
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 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, clever! However, this still doesn't cover defmt.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh yes - defmt is a thing👍

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok given I'm not able to get the exception handler to work with defmt + RTT + probe-rs I don't think it makes sense to address it here

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, I'll handle that part in the future.

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