Module rp2040_hal::uart[][src]

Expand description

Universal Asynchronous Receiver Transmitter (UART)

See Chapter 4 Section 2 of the datasheet for more details

Usage

See examples/uart.rs for a more complete example

use rp2040_hal::{clocks::init_clocks_and_plls, gpio::{Pins, FunctionUart}, pac, sio::Sio, uart::{self, UartPeripheral}, watchdog::Watchdog};

const XOSC_CRYSTAL_FREQ: u32 = 12_000_000; // Typically found in BSP crates

let mut peripherals = pac::Peripherals::take().unwrap();
let sio = Sio::new(peripherals.SIO);
let pins = Pins::new(peripherals.IO_BANK0, peripherals.PADS_BANK0, sio.gpio_bank0, &mut peripherals.RESETS);
let mut watchdog = Watchdog::new(peripherals.WATCHDOG);
let mut clocks = init_clocks_and_plls(XOSC_CRYSTAL_FREQ, peripherals.XOSC, peripherals.CLOCKS, peripherals.PLL_SYS, peripherals.PLL_USB, &mut peripherals.RESETS, &mut watchdog).ok().unwrap();

// Need to perform clock init before using UART or it will freeze.
let uart = UartPeripheral::<_, _>::enable(
        peripherals.UART0,
        &mut peripherals.RESETS,
        uart::common_configs::_9600_8_N_1,
        clocks.peripheral_clock.into(),
    ).unwrap();

// Set up UART on GP0 and GP1 (Pico pins 1 and 2)
let _tx_pin = pins.gpio0.into_mode::<FunctionUart>();
let _rx_pin = pins.gpio1.into_mode::<FunctionUart>();
uart.write_full_blocking(b"Hello World!\r\n");

Modules

Common configurations for UART.

Structs

UART is disabled.

UART is enabled.

When there’s a read error.

A struct holding the configuration for an UART device.

An UART Peripheral based on an underlying UART device.

Enums

Data bits

Error type for UART operations.

Parity The “none” state of parity is represented with the Option type (None).

Possible types of read errors. See Chapter 4, Section 2 §8 - Table 436: “UARTDR Register”

Stop bits

Traits

State of the UART Peripheral.

Trait to handle both underlying devices (UART0 & UART1)