Crate defmt_ringbuf

source ·
Expand description

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"]}

Structs

Traits

Functions

  • init
    Initializes logging to a ring buffer.
  • Reads and removes data from the log buffer.