Expand description
§PioUart Crate
This crate provides a UART implementation using the PIO hardware on the RP2040 microcontroller.
It’s designed to work with the rp2040_hal
crate and provides a UART interface through the Programmable I/O (PIO) subsystem.
§Features
- UART communication using PIO
- Flexible pin assignment for RX and TX
- Customizable baud rate and system frequency settings
- Non-blocking read and write operations
§Usage
To use this crate, ensure that you have rp2040_hal
and embedded-hal
as dependencies in your Cargo.toml
.
You’ll need to configure the PIO and state machines to set up the UART interface.
§Example
use pio_uart::PioUart;
use embedded_io::{Read, Write};
use fugit::ExtU32;
fn main() {
// Normal system initialization
let mut pac = pac::Peripherals::take().unwrap();
let core = pac::CorePeripherals::take().unwrap();
let mut watchdog = hal::Watchdog::new(pac.WATCHDOG);
let clocks = hal::clocks::init_clocks_and_plls(
rp_pico::XOSC_CRYSTAL_FREQ, pac.XOSC, pac.CLOCKS,
pac.PLL_SYS, pac.PLL_USB, &mut pac.RESETS, &mut watchdog,
).ok().unwrap();
let sio = hal::Sio::new(pac.SIO);
let pins = rp_pico::Pins::new(pac.IO_BANK0, pac.PADS_BANK0, sio.gpio_bank0, &mut pac.RESETS);
// Initialize software UART
let mut uart = pio_uart::PioUart::new(
pac.PIO0,
pins.gpio16.reconfigure(),
pins.gpio17.reconfigure(),
&mut pac.RESETS,
19200.Hz(),
125.MHz(),
);
uart.write(b"Hello, UART over PIO!");
let mut buffer = [0u8; 10];
uart.read(&mut buffer);
}
Structs§
- PioUart
- Represents a UART interface using the RP2040’s PIO hardware.
- PioUart
Rx - Represents the Rx part of a UART interface using the RP2040’s PIO hardware.
- PioUart
Tx - Represents the Tx part of a UART interface using the RP2040’s PIO hardware.
- RxProgram
- Token of the already installed UART Rx program. To be obtained with
install_rx_program
. - TxProgram
- Token of the already installed UART Tx program. To be obtained with
install_tx_program
.
Enums§
- PioSerial
Error - Represents errors that can occur in the PIO UART.
Functions§
- install_
rx_ program - Install the UART Rx program in a PIO instance
- install_
tx_ program - Install the UART Tx program in a PIO instance