Skip to content

Commit

Permalink
Add print-log feature to panic_probe
Browse files Browse the repository at this point in the history
  • Loading branch information
t-moe committed Dec 12, 2023
1 parent 5719804 commit 08eda45
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
3 changes: 3 additions & 0 deletions firmware/panic-probe/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand All @@ -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

Expand Down
8 changes: 7 additions & 1 deletion firmware/panic-probe/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 13 additions & 1 deletion firmware/panic-probe/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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);
}
}

0 comments on commit 08eda45

Please sign in to comment.