From 05947e3cb393ae106956b501e10aea5f752479da Mon Sep 17 00:00:00 2001 From: bjoernQ Date: Mon, 2 Sep 2024 13:30:58 +0200 Subject: [PATCH 1/2] Improve CP0-disabled error message --- esp-backtrace/src/lib.rs | 2 +- esp-backtrace/src/xtensa.rs | 14 ++++++++++++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/esp-backtrace/src/lib.rs b/esp-backtrace/src/lib.rs index c51c7742d8d..f023e605aab 100644 --- a/esp-backtrace/src/lib.rs +++ b/esp-backtrace/src/lib.rs @@ -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); diff --git a/esp-backtrace/src/xtensa.rs b/esp-backtrace/src/xtensa.rs index e22e1b5a938..eb0c4425c43 100644 --- a/esp-backtrace/src/xtensa.rs +++ b/esp-backtrace/src/xtensa.rs @@ -1,4 +1,4 @@ -use core::arch::asm; +use core::{arch::asm, fmt::Display}; use crate::MAX_BACKTRACE_ADDRESSES; @@ -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 { @@ -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)] From c272da76e2a1408bc13e984cdfa88c063bc4d901 Mon Sep 17 00:00:00 2001 From: bjoernQ Date: Mon, 2 Sep 2024 13:36:07 +0200 Subject: [PATCH 2/2] CHANGELOG.md --- esp-backtrace/CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/esp-backtrace/CHANGELOG.md b/esp-backtrace/CHANGELOG.md index 8db4528b8cd..ba80eba4950 100644 --- a/esp-backtrace/CHANGELOG.md +++ b/esp-backtrace/CHANGELOG.md @@ -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