2 unstable releases
0.2.0 | Mar 6, 2023 |
---|---|
0.1.0 | Mar 3, 2023 |
#862 in Embedded development
12KB
168 lines
defmt-ringbuf
This crate stores defmt
log messages in a simple ring buffer that is persisted across resets.
You still need to read the messages from the buffer and transfer them to a host for formatting.
License
Licensed under either of
at your option.
Contribution
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in defmt-ringbuf by you shall be licensed as above, without any additional terms or conditions.
lib.rs
:
defmt-ringbuf is a defmt
global logger that logs into
a persistent ring buffer.
The ring buffer is not cleared at startup, i.e. if placed in a static global variable log messages will still be available after a reset.
To use this crate, link to it by importing it somewhere in your project.
use core::mem::MaybeUninit;
use defmt_ringbuf as _;
static mut LOG: MaybeUninit<defmt_ringbuf::RingBuffer<1024>> = MaybeUninit::uninit();
#[entry]
fn main() -> ! {
unsafe {
defmt_ringbuf::init(&mut LOG, || ());
}
// ...
}
Call [init] to initialize logging and [read] to read buffered log data.
Critical section implementation
This crate uses critical-section
to ensure only one thread
is writing to the buffer at a time. You must import a crate that provides a critical-section
implementation
suitable for the current target. See the critical-section
README for details.
For example, for single-core privileged-mode Cortex-M targets, you can add the following to your Cargo.toml.
[dependencies]
cortex-m = { version = "0.7.6", features = ["critical-section-single-core"]}
Dependencies
~1–1.6MB
~28K SLoC