Improve CP0-disabled error message (#2061)

* Improve CP0-disabled error message

* CHANGELOG.md
This commit is contained in:
Björn Quentin 2024-09-02 15:38:10 +02:00 committed by GitHub
parent b620e35ebe
commit d60bafbf05
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 14 additions and 3 deletions

View File

@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added ### Added
### Changed ### Changed
- Print a more helpful message in case of a `Cp0Disabled` exception (#2061)
### Fixed ### Fixed

View File

@ -100,7 +100,7 @@ unsafe fn __user_exception(cause: arch::ExceptionCause, context: arch::Context)
// Unfortunately, a different formatter string is used // Unfortunately, a different formatter string is used
#[cfg(not(feature = "defmt"))] #[cfg(not(feature = "defmt"))]
esp_println::println!("\n\nException occurred '{:?}'", cause); esp_println::println!("\n\nException occurred '{}'", cause);
#[cfg(feature = "defmt")] #[cfg(feature = "defmt")]
defmt::error!("\n\nException occurred '{}'", cause); defmt::error!("\n\nException occurred '{}'", cause);

View File

@ -1,4 +1,4 @@
use core::arch::asm; use core::{arch::asm, fmt::Display};
use crate::MAX_BACKTRACE_ADDRESSES; use crate::MAX_BACKTRACE_ADDRESSES;
@ -11,7 +11,7 @@ pub(super) const RA_OFFSET: usize = 3;
/// Exception Cause /// Exception Cause
#[doc(hidden)] #[doc(hidden)]
#[derive(Debug, Clone, Copy)] #[derive(Debug, Clone, Copy, PartialEq)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))] #[cfg_attr(feature = "defmt", derive(defmt::Format))]
#[repr(C)] #[repr(C)]
pub enum ExceptionCause { pub enum ExceptionCause {
@ -99,6 +99,16 @@ pub enum ExceptionCause {
None = 255, 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)] #[doc(hidden)]
#[allow(non_snake_case)] #[allow(non_snake_case)]
#[derive(Clone, Copy)] #[derive(Clone, Copy)]