From 56af0b3af6b59417376e3c9df687d47837a5518d Mon Sep 17 00:00:00 2001 From: t-moe Date: Tue, 12 Dec 2023 12:06:53 +0100 Subject: [PATCH] Add print-log feature to panic_probe --- firmware/panic-probe/Cargo.toml | 3 +++ firmware/panic-probe/README.md | 8 +++++++- firmware/panic-probe/src/lib.rs | 14 +++++++++++++- 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/firmware/panic-probe/Cargo.toml b/firmware/panic-probe/Cargo.toml index 32146852..f213239a 100644 --- a/firmware/panic-probe/Cargo.toml +++ b/firmware/panic-probe/Cargo.toml @@ -12,6 +12,7 @@ version = "0.4.0" [dependencies] defmt = { version = "0.3", path = "../../defmt", optional = true } +log = { version = "0.4", optional = true } rtt-target = { version = "0.4", optional = true } semihosting = "0.1.4" @@ -27,6 +28,8 @@ riscv = "0.10.1" print-rtt = ["rtt-target"] # Print the panic message using `defmt`. print-defmt = ["defmt", "defmt-error"] +# Print the panic message using `log` +print-log = ["log"] defmt-error = [] # internal feature, do not use diff --git a/firmware/panic-probe/README.md b/firmware/panic-probe/README.md index 0535cc8a..2a55ae7b 100644 --- a/firmware/panic-probe/README.md +++ b/firmware/panic-probe/README.md @@ -4,7 +4,13 @@ [`probe-rs`]: https://github.com/probe-rs/probe-rs -`panic-probe` can optionally log the panic message using the [`defmt`] logging framework. +`panic-probe` can optionally log the panic message. Enabled one of the following features for that: +* `print-defmt` to print via `defmt::error!(..)` +* `print-log` to print via `log::error!(..)` +* `print-rtt` to print via `rtt_target::rprintln(..)` + + + using the [`defmt`] logging framework. This functionality can be enabled through the `print-defmt` Cargo feature. [`defmt`]: https://github.com/knurling-rs/defmt diff --git a/firmware/panic-probe/src/lib.rs b/firmware/panic-probe/src/lib.rs index 82fa3554..75b60492 100644 --- a/firmware/panic-probe/src/lib.rs +++ b/firmware/panic-probe/src/lib.rs @@ -35,7 +35,10 @@ mod imp { #[cfg(feature = "print-defmt")] use crate::print_defmt::print; - #[cfg(not(any(feature = "print-rtt", feature = "print-defmt")))] + #[cfg(feature = "print-log")] + use crate::print_log::print; + + #[cfg(not(any(feature = "print-rtt", feature = "print-defmt", feature = "print-log")))] fn print(_: &core::panic::PanicInfo) {} #[panic_handler] @@ -100,3 +103,12 @@ mod print_defmt { defmt::error!("{}", defmt::Display2Format(info)); } } + +#[cfg(feature = "print-log")] +mod print_log { + use core::panic::PanicInfo; + + pub fn print(info: &PanicInfo) { + log::error!("{}", info); + } +}