Code Monkey home page Code Monkey logo

defmt-serial's Introduction

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} 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)

defmt-serial's People

Contributors

gauteh avatar dave-vallance avatar esden avatar kolegs avatar brandonros avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.