Skip to main content

Module uart

Module uart 

Source
Expand description

Controls UART peripherals (UART0, UART1, UART2).

Notice that UART0 is typically already used for loading firmware and logging. Therefore use UART1 and UART2 in your application. Any pin can be used for rx and tx.

§Example

Create a serial peripheral and write to serial port.

use std::fmt::Write;
use esp_idf_hal::prelude::*;
use esp_idf_hal::uart;

let peripherals = Peripherals::take().unwrap();
let pins = peripherals.pins;

let config = uart::config::Config::default().baudrate(Hertz(115_200));

let mut uart: uart::UartDriver = uart::UartDriver::new(
    peripherals.uart1,
    pins.gpio1,
    pins.gpio3,
    Option::<AnyIOPin>::None,
    Option::<AnyIOPin>::None,
    &config
).unwrap();

for i in 0..10 {
    writeln!(uart, "{:}", format!("count {:}", i)).unwrap();
}

§TODO

  • Add all extra features esp32 supports
  • Free APB lock when TX is idle (and no RX used)
  • Address errata 3.17: UART fifo_cnt is inconsistent with FIFO pointer

Modules§

config
UART configuration

Structs§

AsyncUartDriver
AsyncUartRxDriver
AsyncUartTxDriver
SerialError
UART0
UART1
UartDriver
Serial abstraction
UartEvent
UartRxDriver
Serial receiver
UartTxDriver
Serial transmitter

Enums§

UartEventPayload

Traits§

Uart

Functions§

remaining_unread_bytes
remaining_write_capacity

Type Aliases§

UartConfig