8 releases (breaking)

0.8.0 Feb 9, 2024
0.7.0 Oct 11, 2023
0.6.0 Sep 13, 2022
0.5.0 Aug 2, 2022
0.1.0 Jun 28, 2022

#377 in Hardware support

40 downloads per month

MIT license

150KB
78 lines

Crates.io Documentation tests

defmt-serial

A defmt target for logging over a serial port. Have a look at examples to see how to use library example-artemis or example-pi-pico. You can also try it out in a hosted environment: example-std. To parse the logs have a look at parsing logs.

static SERIAL: StaticCell<hal::uart::Uart0> = StaticCell::new();

#[entry]
fn main() -> ! {
    let mut dp = hal::pac::Peripherals::take().unwrap();
    let pins = hal::gpio::Pins::new(dp.GPIO);

    // set up serial
    let serial = hal::uart::Uart0::new(dp.UART0, pins.tx0, pins.rx0);
    defmt_serial::defmt_serial(SERIAL.init(serial));

    defmt::info!("Hello from defmt!");

    loop {
        asm::wfi();
    }
}

Remember to set the DEFMT_LOG variable when testing, e.g.:

$ cd example-std/
$ DEFMT_LOG=debug cargo run

Parsing logs

The easiest way to parse the logs is to use socat and defmt-print together. For example:

socat ${PORT},rawer,b${BAUDRATE},crnl STDOUT | defmt-print -e ${ELF}

Just replace ${PORT}, ${BAUDRATE} and ${ELF} with correct values.

To install the tools on Ubuntu 22.04 run these commands:

apt install socat
cargo install defmt-print

Dependencies

~0.6–1.1MB
~24K SLoC