aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--tests/nrf/Cargo.toml2
-rw-r--r--tests/nrf/src/bin/buffered_uart_full.rs72
2 files changed, 73 insertions, 1 deletions
diff --git a/tests/nrf/Cargo.toml b/tests/nrf/Cargo.toml
index f7a104090..a3393f7e9 100644
--- a/tests/nrf/Cargo.toml
+++ b/tests/nrf/Cargo.toml
@@ -12,7 +12,7 @@ embassy-sync = { version = "0.4.0", path = "../../embassy-sync", features = ["de
12embassy-executor = { version = "0.3.1", path = "../../embassy-executor", features = ["arch-cortex-m", "executor-thread", "defmt", "nightly", "integrated-timers"] } 12embassy-executor = { version = "0.3.1", path = "../../embassy-executor", features = ["arch-cortex-m", "executor-thread", "defmt", "nightly", "integrated-timers"] }
13embassy-time = { version = "0.1.5", path = "../../embassy-time", features = ["defmt", "nightly", "unstable-traits", "defmt-timestamp-uptime"] } 13embassy-time = { version = "0.1.5", path = "../../embassy-time", features = ["defmt", "nightly", "unstable-traits", "defmt-timestamp-uptime"] }
14embassy-nrf = { version = "0.1.0", path = "../../embassy-nrf", features = ["defmt", "nightly", "unstable-traits", "nrf52840", "time-driver-rtc1", "gpiote", "unstable-pac"] } 14embassy-nrf = { version = "0.1.0", path = "../../embassy-nrf", features = ["defmt", "nightly", "unstable-traits", "nrf52840", "time-driver-rtc1", "gpiote", "unstable-pac"] }
15embedded-io-async = { version = "0.6.0" } 15embedded-io-async = { version = "0.6.0", features = ["defmt-03"] }
16embassy-net = { version = "0.2.0", path = "../../embassy-net", features = ["defmt", "tcp", "dhcpv4", "medium-ethernet", "nightly"] } 16embassy-net = { version = "0.2.0", path = "../../embassy-net", features = ["defmt", "tcp", "dhcpv4", "medium-ethernet", "nightly"] }
17embassy-net-esp-hosted = { version = "0.1.0", path = "../../embassy-net-esp-hosted", features = ["defmt"] } 17embassy-net-esp-hosted = { version = "0.1.0", path = "../../embassy-net-esp-hosted", features = ["defmt"] }
18embassy-net-enc28j60 = { version = "0.1.0", path = "../../embassy-net-enc28j60", features = ["defmt"] } 18embassy-net-enc28j60 = { version = "0.1.0", path = "../../embassy-net-enc28j60", features = ["defmt"] }
diff --git a/tests/nrf/src/bin/buffered_uart_full.rs b/tests/nrf/src/bin/buffered_uart_full.rs
new file mode 100644
index 000000000..2db8f88d3
--- /dev/null
+++ b/tests/nrf/src/bin/buffered_uart_full.rs
@@ -0,0 +1,72 @@
1#![no_std]
2#![no_main]
3#![feature(type_alias_impl_trait)]
4teleprobe_meta::target!(b"nrf52840-dk");
5
6use defmt::{assert_eq, *};
7use embassy_executor::Spawner;
8use embassy_nrf::buffered_uarte::{self, BufferedUarte};
9use embassy_nrf::{bind_interrupts, peripherals, uarte};
10use embedded_io_async::{Read, Write};
11use {defmt_rtt as _, panic_probe as _};
12
13bind_interrupts!(struct Irqs {
14 UARTE0_UART0 => buffered_uarte::InterruptHandler<peripherals::UARTE0>;
15});
16
17#[embassy_executor::main]
18async fn main(_spawner: Spawner) {
19 let p = embassy_nrf::init(Default::default());
20 let mut config = uarte::Config::default();
21 config.parity = uarte::Parity::EXCLUDED;
22 config.baudrate = uarte::Baudrate::BAUD1M;
23
24 let mut tx_buffer = [0u8; 1024];
25 let mut rx_buffer = [0u8; 1024];
26
27 let mut u = BufferedUarte::new(
28 p.UARTE0,
29 p.TIMER0,
30 p.PPI_CH0,
31 p.PPI_CH1,
32 p.PPI_GROUP0,
33 Irqs,
34 p.P1_03,
35 p.P1_02,
36 config.clone(),
37 &mut rx_buffer,
38 &mut tx_buffer,
39 );
40
41 info!("uarte initialized!");
42
43 let (mut rx, mut tx) = u.split();
44
45 let mut buf = [0; 1024];
46 for (j, b) in buf.iter_mut().enumerate() {
47 *b = j as u8;
48 }
49
50 // Write 1024b. This causes the rx buffer to get exactly full.
51 unwrap!(tx.write_all(&buf).await);
52 unwrap!(tx.flush().await);
53
54 // Read those 1024b.
55 unwrap!(rx.read_exact(&mut buf).await);
56 for (j, b) in buf.iter().enumerate() {
57 assert_eq!(*b, j as u8);
58 }
59
60 // The buffer should now be unclogged. Write 1024b again.
61 unwrap!(tx.write_all(&buf).await);
62 unwrap!(tx.flush().await);
63
64 // Read should work again.
65 unwrap!(rx.read_exact(&mut buf).await);
66 for (j, b) in buf.iter().enumerate() {
67 assert_eq!(*b, j as u8);
68 }
69
70 info!("Test OK");
71 cortex_m::asm::bkpt();
72}