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::{Clock, clocks::init_clocks_and_plls, gpio::{Pins, FunctionUart}, pac, sio::Sio, uart::{self, DataBits, StopBits, UartConfig, UartPeripheral}, watchdog::Watchdog};
use fugit::RateExtU32;
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();
// Set up UART on GP0 and GP1 (Pico pins 1 and 2)
let pins = (
pins.gpio0.into_function(),
pins.gpio1.into_function(),
);
// Need to perform clock init before using UART or it will freeze.
let uart = UartPeripheral::new(peripherals.UART0, pins, &mut peripherals.RESETS)
.enable(
UartConfig::new(9600.Hz(), DataBits::Eight, None, StopBits::One),
clocks.peripheral_clock.freq(),
).unwrap();
uart.write_full_blocking(b"Hello World!\r\n");
Modules§
- common_
configs Deprecated - Common configurations for UART.
Structs§
- Disabled
- UART is disabled.
- Enabled
- UART is enabled.
- Pins
- Customizable Uart pinout, allowing you to set the pins individually.
- Read
Error - When there’s a read error.
- Reader
- Half of an
UartPeripheral
that is only capable of reading. Obtained by callingUartPeripheral::split()
- Uart
Config - A struct holding the configuration for an UART device.
- Uart
Peripheral - An UART Peripheral based on an underlying UART device.
- Validated
PinCts - A runtime validated Cts pin for uart.
- Validated
PinRts - A runtime validated Rts pin for uart.
- Validated
PinRx - A runtime validated Rx pin for uart.
- Validated
PinTx - A runtime validated Tx pin for uart.
- Writer
- Half of an
UartPeripheral
that is only capable of writing. Obtained by callingUartPeripheral::split()
Enums§
- Data
Bits - Data bits
- Error
- Error type for UART operations.
- Fifo
Watermark - Rx/Tx FIFO Watermark
- Parity
- Parity
- Read
Error Type - Possible types of read errors. See Chapter 4, Section 2 §8 - Table 436: “UARTDR Register”
- Stop
Bits - Stop bits
Traits§
- State
- State of the UART Peripheral.
- Uart
Device - Trait to handle both underlying devices (UART0 & UART1)
- Valid
Option Cts - Indicates a valid optional Cts pin for UART0 or UART1
- Valid
Option Rts - Indicates a valid optional Rts pin for UART0 or UART1
- Valid
Option Rx - Indicates a valid optional Rx pin for UART0 or UART1
- Valid
Option Tx - Indicates a valid optional Tx pin for UART0 or UART1
- Valid
PinCts - Indicates a valid Cts pin for UART0 or UART1
- Valid
PinId Cts - Indicates a valid Cts pin for UART0 or UART1
- Valid
PinId Rts - Indicates a valid Rts pin for UART0 or UART1
- Valid
PinId Rx - Indicates a valid Rx pin for UART0 or UART1
- Valid
PinId Tx - Indicates a valid Tx pin for UART0 or UART1
- Valid
PinRts - Indicates a valid Rts pin for UART0 or UART1
- Valid
PinRx - Indicates a valid Rx pin for UART0 or UART1
- Valid
PinTx - Indicates a valid Tx pin for UART0 or UART1
- Valid
Uart Pinout - Declares a valid UART pinout.