https://github.com/cobular/defmt-serial
https://github.com/cobular/defmt-serial
Last synced: 3 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/cobular/defmt-serial
- Owner: Cobular
- Created: 2024-05-28T22:46:39.000Z (about 2 years ago)
- Default Branch: eh-1
- Last Pushed: 2024-05-29T02:22:17.000Z (about 2 years ago)
- Last Synced: 2026-01-31T21:05:12.076Z (5 months ago)
- Language: Rust
- Size: 473 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
[](https://crates.io/crates/defmt-serial)
[](https://docs.rs/defmt-serial/)
[](https://github.com/gauteh/defmt-serial/actions/workflows/rust.yml)
# defmt-serial
A [defmt](https://github.com/knurling-rs/defmt) target for logging over a serial
port. Have a look at examples to see how to use library
[example-artemis](example-artemis) or [example-pi-pico](example-pi-pico). You
can also try it out in a hosted environment: [example-std](example-std). To
parse the logs have a look at [parsing logs](#Parsing-logs).
```rust
static SERIAL: StaticCell = 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} 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)