Module imxrt_hal::lpuart

source ·
Expand description

Low-power universal asynchronous receiver / transmitter.

Use the LPUART peripheral to perform reads and writes with a serial device. Features include

  • configurable baud rates (depends on input clock frequency)
  • parity bits: none, even, odd
  • inverted TX and RX lines
  • TX and RX FIFOs with configurable watermarks
  • DMA transfers and receives
  • Non-blocking and blocking implementations of embedded-hal serial traits.

§Example

Demonstrates how to create and configure an LPUART peripheral. To see an example of LPUART clock configuration, see the ccm::uart_clk documentation. For more information on the DMA API, see the dma examples.

use imxrt_hal as hal;
use hal::lpuart::{Baud, Direction, Lpuart, Parity, Pins, Status, Watermark};
use imxrt_ral as ral;

let (gpio_ad_b1_02, gpio_ad_b1_03) = // Handle to LPUART2 TX and RX pins...

let registers = unsafe { ral::lpuart::LPUART2::instance() };
let pins = Pins { tx: gpio_ad_b1_02, rx: gpio_ad_b1_03 };
let mut lpuart2 = Lpuart::new(registers, pins);

const BAUD: Baud = Baud::compute(UART_CLKC_HZ, 115200);
lpuart2.disable(|lpuart2| {
    lpuart2.set_baud(&BAUD);
    lpuart2.set_parity(Parity::ODD);
    lpuart2.enable_fifo(Watermark::tx(4));
    lpuart2.disable_fifo(Direction::Rx);
    lpuart2.set_inversion(Direction::Rx, true);
});

// Fill the transmit FIFO with 0xAA...
while lpuart2.status().contains(Status::TRANSMIT_EMPTY) {
    lpuart2.write_byte(0xAA);
}

// Schedule a DMA receive...
let mut buffer = [0u8; 64];
lpuart2.dma_read(&mut dma_channel, &mut buffer)
    .await.ok()?;

// Release the peripheral instance...
let (lpuart2, pins) = lpuart2.release();

// Reconstruct without the pins...
let mut lpuart2 = Lpuart::without_pins(lpuart2);

Structs§

Enums§