Crates.io | pio-uart |
lib.rs | pio-uart |
version | 0.3.0 |
source | src |
created_at | 2023-12-17 18:42:45.011401 |
updated_at | 2024-09-09 12:28:54.499399 |
description | A software UART implementation for the RP2040 using the PIO feature. |
homepage | |
repository | https://github.com/Sympatron/pio-uart |
max_upload_size | |
id | 1072680 |
size | 76,500 |
The pio-uart
crate provides a software UART implementation for the Raspberry Pi RP2040 microcontroller, utilizing its Programmable I/O (PIO) feature. This crate enables serial communication on the RP2040 without using its dedicated UART hardware blocks, allowing for greater flexibility in pin selection and potentially freeing up hardware UARTs for other purposes.
Add pio-uart
as a dependency:
cargo add pio-uart
Basic usage of the pio-uart
crate involves setting up the PIO UART with desired pins and baud rate, and then using it for reading and writing data.
Example:
use embedded_io::{Read, Write};
use fugit::RateExtU32;
use pio_uart::PioUart;
use rp2040_hal as hal;
use rp2040_hal::pac;
fn main() {
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 = PioUart::new(
pac.PIO0,
pins.gpio16.reconfigure(),
pins.gpio17.reconfigure(),
&mut pac.RESETS,
19200.Hz(),
125.MHz(),
)
.enable();
uart.write(b"Hello, UART over PIO!");
let mut buffer = [0u8; 10];
uart.read(&mut buffer);
}
For detailed documentation, examples, and API reference, visit crates.io.
This crate is licensed under the BSD-3-Clause license.
Contributions are welcome. Please follow the standard Rust community contribution guidelines.
This crate is provided as-is, with no guarantees of functionality or stability. The developers are not responsible for any damage caused by using this crate.