Module esp_idf_svc::hal::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 (eg rs485, etc. etc.)
- Free APB lock when TX is idle (and no RX used)
- Address errata 3.17: UART fifo_cnt is inconsistent with FIFO pointer
Modules§
- UART configuration
Structs§
- Serial abstraction
- Serial receiver
- Serial transmitter