aboutsummaryrefslogtreecommitdiff
path: root/tests/rp/src
diff options
context:
space:
mode:
authorMathias <[email protected]>2022-09-29 10:00:13 +0200
committerMathias <[email protected]>2022-09-29 10:00:13 +0200
commit7ee7109508b463f98ea9ae08e061aeaca28016e6 (patch)
tree50723244067224c6c32603e21fbe8ec36c76898e /tests/rp/src
parent18dc0dea636daa6e48aa9208b5a74cdfedc8b513 (diff)
parent77ece3f903735b50f265ddd43520c50e0f28c1a1 (diff)
Rebase on master
Diffstat (limited to 'tests/rp/src')
-rw-r--r--tests/rp/src/bin/uart_buffered.rs44
1 files changed, 44 insertions, 0 deletions
diff --git a/tests/rp/src/bin/uart_buffered.rs b/tests/rp/src/bin/uart_buffered.rs
new file mode 100644
index 000000000..9cc20bb98
--- /dev/null
+++ b/tests/rp/src/bin/uart_buffered.rs
@@ -0,0 +1,44 @@
1#![no_std]
2#![no_main]
3#![feature(type_alias_impl_trait)]
4
5use defmt::{assert_eq, *};
6use embassy_executor::Spawner;
7use embassy_rp::interrupt;
8use embassy_rp::uart::{BufferedUart, Config, State, Uart};
9use embedded_io::asynch::{Read, Write};
10use {defmt_rtt as _, panic_probe as _};
11
12#[embassy_executor::main]
13async fn main(_spawner: Spawner) {
14 let p = embassy_rp::init(Default::default());
15 info!("Hello World!");
16
17 let (tx, rx, uart) = (p.PIN_0, p.PIN_1, p.UART0);
18
19 let config = Config::default();
20 let uart = Uart::new_blocking(uart, tx, rx, config);
21
22 let irq = interrupt::take!(UART0_IRQ);
23 let tx_buf = &mut [0u8; 16];
24 let rx_buf = &mut [0u8; 16];
25 let mut state = State::new();
26 let mut uart = BufferedUart::new(&mut state, uart, irq, tx_buf, rx_buf);
27
28 // Make sure we send more bytes than fits in the FIFO, to test the actual
29 // bufferedUart.
30
31 let data = [
32 1_u8, 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, 29,
33 30, 31, 32,
34 ];
35 uart.write_all(&data).await.unwrap();
36 info!("Done writing");
37
38 let mut buf = [0; 32];
39 uart.read_exact(&mut buf).await.unwrap();
40 assert_eq!(buf, data);
41
42 info!("Test OK");
43 cortex_m::asm::bkpt();
44}