Crate defmt_serial

source ·
Expand description

A defmt target for logging messages over a serial interface. The serial interface must implement [embedded_hal::blocking::serial::Write].

The received defmt-frames can be read using e.g. socat and defmt-print, so that you can set it up as cargo runner. See the example-artemis for how to do that.

You can also use it to have defmt work on std/hosted OSes, see example-std.

#![no_std]
#![no_main]


use panic_probe as _;
use cortex_m::asm;
use cortex_m_rt::entry;
use ambiq_hal::{self as hal, prelude::*};

use static_cell::StaticCell;
use defmt;
use defmt_serial as _;

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

Traits§

  • All of this nonsense is to try and erase the Error type of the embedded_hal::serial::nb::Write implementor.

Functions§

  • Assign a serial peripheral to receive defmt-messages.
  • Release the serial port from defmt.