Crates.io | defmt-serial |
lib.rs | defmt-serial |
version | 0.10.0 |
source | src |
created_at | 2022-06-28 09:53:19.099064 |
updated_at | 2024-06-07 08:24:37.988003 |
description | Log defmt-messages over serial |
homepage | |
repository | https://github.com/gauteh/defmt-serial |
max_upload_size | |
id | 614736 |
size | 173,394 |
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
The easiest way to parse the logs is to use socat
and defmt-print
together.
For example:
$ socat ${PORT},rawer,b${BAUDRATE} 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
Note that on Mac OS it seems that socat
is broken for this purpose. Use stty
and cat
in stead:
$ (stty speed 115200 >/dev/null && cat) </dev/cu.usbserial-10 | defmt-print -e $(ELF)