defmt
In this chapter, we will cover defmt
, a highly efficient logging framework, and how to use it in the no_std
environment.
defmt
Ecosystem
esp-println
, esp-backtrace
and espflash
/cargo-espflash
provide mechanisms to use defmt
:
espflash
has support for different logging formats, one of them beingdefmt
.espflash
requires framming bytes as when usingdefmt
it also needs to print non-defmt
messages, like the bootloader prints.- It's important to note that other
defmt
-enabled tools likeprobe-rs
won't be able to parse these messages due to the extra framing bytes.
- It's important to note that other
- Uses rzcobs encoding
esp-println
has adefmt-espflash
feature, which adds framming bytes soespflash
knows that is adefmt
message.esp-backtrace
has adefmt
feature that usesdefmt
logging to print panic and exception handler messages.
Setup
✅ Go to intro/defmt
directory.
✅ Open the prepared project skeleton in intro/defmt
.
intro/defmt/examples/defmt.rs
contains the solution. You can run it with the following command:
cargo run --release --example defmt
Exercise
✅ Make sure the defmt-espflash
feature of esp-println
is enabled.
✅ Make sure the defmt
feature of esp-backtrace
is enabled.
✅ Update the linking process in the .cargo/config.toml
.
✅ Make sure, the defmt
crate is added to the dependencies.
✅ Make sure you are building esp_println
and esp_backtrace
use esp_backtrace as _;
use esp_println as _;
✅ Use the defmt::println!
or any of the logging defmt
macros to print a message.
- If you want to use any of the logging macros like
info
,debug
- Enable the
log
feature ofesp-println
- When building the app, set
DEFMT_LOG
level.
- Enable the
✅ Add a panic!
macro to trigger a panic with a defmt
message.