[][src]Module imxrt_uart_log::blocking

A logging implementation that blocks when writing data

The logger is simple to set up, and it will accept as much data as you'd like to write. To log data,

  1. Configure a UART peripheral with baud rates, parities, inversions, etc.
  2. Call init with the UART transfer half, and a LoggingConfig. If the default logging behavior is acceptable, use Default::default() to skip logging configuration.
  3. Use the macros from the log crate to write data

Use-cases

  • Simply debugging programs and libraries
  • Frequently logging large strings
  • panic!() handlers, and printing-out panic messages
  • Logging in interrupt and fault handlers

Implementation

The implementation blocks, buffering data into the UART transfer FIFO, until the final bytes are enqueued in the FIFO. The implementation logs data in an interrupt free critical section. Interrupts will not preempt logging, and logging may reduce the system's responsiveness. To evaluate some simple performance measurements, see Performance.

Consider using the largest size transfer FIFO to support UART data transfer. See the example for more details.

Example

use imxrt_hal;
use imxrt_uart_log;

let mut peripherals = imxrt_hal::Peripherals::take().unwrap();

let uarts = peripherals.uart.clock(
    &mut peripherals.ccm.handle,
    imxrt_hal::ccm::uart::ClockSelect::OSC,
    imxrt_hal::ccm::uart::PrescalarSelect::DIVIDE_1,
);

let mut uart = uarts
    .uart2
    .init(
        peripherals.iomuxc.ad_b1.p02,
        peripherals.iomuxc.ad_b1.p03,
        115_200,
    )
    .unwrap();

// Consider using a large TX FIFO size
uart.set_tx_fifo(core::num::NonZeroU8::new(4));
// Set other UART configurations...

let (tx, rx) = uart.split();
imxrt_uart_log::blocking::init(tx, Default::default()).unwrap();

// At this point, you may use log macros to write data.
log::info!("Hello world!");

Functions

init

Initialize the blocking logger with a UART's transfer half