2 unstable releases

0.2.0 Mar 6, 2023
0.1.0 Mar 3, 2023

#914 in Embedded development


168 lines


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.


Licensed under either of

at your option.


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.


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();

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.

cortex-m = { version = "0.7.6", features = ["critical-section-single-core"]}


~31K SLoC