aboutsummaryrefslogtreecommitdiff
path: root/examples/rp23/src/bin/uart_buffered_split.rs
diff options
context:
space:
mode:
Diffstat (limited to 'examples/rp23/src/bin/uart_buffered_split.rs')
-rw-r--r--examples/rp23/src/bin/uart_buffered_split.rs74
1 files changed, 74 insertions, 0 deletions
diff --git a/examples/rp23/src/bin/uart_buffered_split.rs b/examples/rp23/src/bin/uart_buffered_split.rs
new file mode 100644
index 000000000..f7acdade9
--- /dev/null
+++ b/examples/rp23/src/bin/uart_buffered_split.rs
@@ -0,0 +1,74 @@
1//! This example shows how to use UART (Universal asynchronous receiver-transmitter) in the RP2040 chip.
2//!
3//! No specific hardware is specified in this example. If you connect pin 0 and 1 you should get the same data back.
4//! The Raspberry Pi Debug Probe (https://www.raspberrypi.com/products/debug-probe/) could be used
5//! with its UART port.
6
7#![no_std]
8#![no_main]
9
10use defmt::*;
11use embassy_executor::Spawner;
12use embassy_rp::bind_interrupts;
13use embassy_rp::peripherals::UART0;
14use embassy_rp::uart::{BufferedInterruptHandler, BufferedUart, BufferedUartRx, Config};
15use embassy_time::Timer;
16use embedded_io_async::{Read, Write};
17use static_cell::StaticCell;
18use {defmt_rtt as _, panic_probe as _};
19use embassy_rp::block::ImageDef;
20
21#[link_section = ".start_block"]
22#[used]
23pub static IMAGE_DEF: ImageDef = ImageDef::secure_exe();
24
25// Program metadata for `picotool info`
26#[link_section = ".bi_entries"]
27#[used]
28pub static PICOTOOL_ENTRIES: [embassy_rp::binary_info::EntryAddr; 4] = [
29 embassy_rp::binary_info_rp_cargo_bin_name!(),
30 embassy_rp::binary_info_rp_cargo_version!(),
31 embassy_rp::binary_info_rp_program_description!(c"Blinky"),
32 embassy_rp::binary_info_rp_program_build_attribute!(),
33];
34
35
36bind_interrupts!(struct Irqs {
37 UART0_IRQ => BufferedInterruptHandler<UART0>;
38});
39
40#[embassy_executor::main]
41async fn main(spawner: Spawner) {
42 let p = embassy_rp::init(Default::default());
43 let (tx_pin, rx_pin, uart) = (p.PIN_0, p.PIN_1, p.UART0);
44
45 static TX_BUF: StaticCell<[u8; 16]> = StaticCell::new();
46 let tx_buf = &mut TX_BUF.init([0; 16])[..];
47 static RX_BUF: StaticCell<[u8; 16]> = StaticCell::new();
48 let rx_buf = &mut RX_BUF.init([0; 16])[..];
49 let uart = BufferedUart::new(uart, Irqs, tx_pin, rx_pin, tx_buf, rx_buf, Config::default());
50 let (mut tx, rx) = uart.split();
51
52 unwrap!(spawner.spawn(reader(rx)));
53
54 info!("Writing...");
55 loop {
56 let data = [
57 1u8, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28,
58 29, 30, 31,
59 ];
60 info!("TX {:?}", data);
61 tx.write_all(&data).await.unwrap();
62 Timer::after_secs(1).await;
63 }
64}
65
66#[embassy_executor::task]
67async fn reader(mut rx: BufferedUartRx<'static, UART0>) {
68 info!("Reading...");
69 loop {
70 let mut buf = [0; 31];
71 rx.read_exact(&mut buf).await.unwrap();
72 info!("RX {:?}", buf);
73 }
74}