3 unstable releases

0.1.1 Apr 10, 2023
0.1.0 Apr 4, 2023
0.0.0 Mar 21, 2023

#1417 in Embedded development

Download history 199/week @ 2024-02-26 134/week @ 2024-03-04 219/week @ 2024-03-11 100/week @ 2024-03-18 197/week @ 2024-03-25 132/week @ 2024-04-01 268/week @ 2024-04-08 255/week @ 2024-04-15 121/week @ 2024-04-22 53/week @ 2024-04-29 36/week @ 2024-05-06 176/week @ 2024-05-13 58/week @ 2024-05-20 71/week @ 2024-05-27 145/week @ 2024-06-03 126/week @ 2024-06-10

410 downloads per month

MIT/Apache

36KB
454 lines

defmt-brtt: defmt over rtt and bbq, simultaneously!

This crate combines the functionality of defmt-rtt and defmt-bbq into one single crate.

This allows you to retrieve data over RTT, but also to pump it out over some other transport by reading the data from a bbqueue.

Even if that is not a use-case you're interested in, you can also defmt-brtt as an easier way of switching between using RTT and/or BBQueue as your defmt transport.

Features

  • rtt: activate the RTT transport (works exactly like defmt-rtt, except for Buffer Size).
  • bbq: activate the BBQueue transport (works exactly like defmt-bbq, except for Buffer Size).
  • async-await: add a function to defmt_brtt::DefmtConsumer that enables async-waiting for log data.

You must activate at least one of rtt and bbq.

Buffer Size

To configure the buffer size used by defmt-brtt, you can set the environment variable DEFMT_BRTT_BUFFER_SIZE to the desired size.

For example, if we'd want to use a 512 byte internal buffer, we would run DEFMT_BRTT_BUFFER_SIZE=512 cargo build in the build directory of a project.

Note that defmt-brtt assigned one buffer of size DEFMT_BRTT_BUFFER_SIZE once for both rtt and bbq, if those features are activated.

User code required for use

To use the defmt logger implementation provided by defmt-brtt, you must always add insert the following use statement somewhere in your project:

use defmt_brtt as _;

rtt

To use the rtt functionality of this crate, you only need to do is activate the rtt feature (activated by default).

bbq

To use the bbq functionality of this crate, you must activate the bbq feature (activated by default). You must call defmt_brtt::init and use the returned DefmtConsumer to consume the defmt data.

The data that is produced by the DefmtConsumer can then be transported and fed to a decoder, such as defmt-print, that will reconstruct the log messages from the defmt data.

fn main() {
    let logger = defmt_brtt::init();

    loop {
        if let Some(grant) = logger.read() {
            let written_bytes = write_my_log_data_over_usb(&grant).ok();
            // The step below is optional. Dropping the `Grant` releases
            // all read bytes.
            grant.release(written_bytes);
        }
    }
}

// If you have the `async-await` feature enabled, you
// can also do the following:
async fn read_logs(consumer: DefmtConsumer) {
    loop {
        let grant = logger.wait_for_log().await;
        let written_bytes = write_my_log_data_over_usb(&grant).ok();
        // The step below is optional. Dropping the `Grant` releases
        // all read bytes.
        grant.release(written_bytes);
    }
}

Dependencies

~0.6–1.1MB
~24K SLoC