diff options
| author | Dario Nieuwenhuis <[email protected]> | 2023-11-14 00:00:39 +0100 |
|---|---|---|
| committer | Dario Nieuwenhuis <[email protected]> | 2023-11-14 00:22:30 +0100 |
| commit | 6ccd8c051e657a233fcdc9040ad0b6aaa2b357e5 (patch) | |
| tree | aee7bb0e82cba313719255f57f185a15183c9368 /tests | |
| parent | c46418f123820e375778e65a90e8589d7d665311 (diff) | |
nrf/buffered_uarte: add test for recovering from buffer full.
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/nrf/Cargo.toml | 2 | ||||
| -rw-r--r-- | tests/nrf/src/bin/buffered_uart_full.rs | 72 |
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 | |||
| 12 | embassy-executor = { version = "0.3.1", path = "../../embassy-executor", features = ["arch-cortex-m", "executor-thread", "defmt", "nightly", "integrated-timers"] } | 12 | embassy-executor = { version = "0.3.1", path = "../../embassy-executor", features = ["arch-cortex-m", "executor-thread", "defmt", "nightly", "integrated-timers"] } |
| 13 | embassy-time = { version = "0.1.5", path = "../../embassy-time", features = ["defmt", "nightly", "unstable-traits", "defmt-timestamp-uptime"] } | 13 | embassy-time = { version = "0.1.5", path = "../../embassy-time", features = ["defmt", "nightly", "unstable-traits", "defmt-timestamp-uptime"] } |
| 14 | embassy-nrf = { version = "0.1.0", path = "../../embassy-nrf", features = ["defmt", "nightly", "unstable-traits", "nrf52840", "time-driver-rtc1", "gpiote", "unstable-pac"] } | 14 | embassy-nrf = { version = "0.1.0", path = "../../embassy-nrf", features = ["defmt", "nightly", "unstable-traits", "nrf52840", "time-driver-rtc1", "gpiote", "unstable-pac"] } |
| 15 | embedded-io-async = { version = "0.6.0" } | 15 | embedded-io-async = { version = "0.6.0", features = ["defmt-03"] } |
| 16 | embassy-net = { version = "0.2.0", path = "../../embassy-net", features = ["defmt", "tcp", "dhcpv4", "medium-ethernet", "nightly"] } | 16 | embassy-net = { version = "0.2.0", path = "../../embassy-net", features = ["defmt", "tcp", "dhcpv4", "medium-ethernet", "nightly"] } |
| 17 | embassy-net-esp-hosted = { version = "0.1.0", path = "../../embassy-net-esp-hosted", features = ["defmt"] } | 17 | embassy-net-esp-hosted = { version = "0.1.0", path = "../../embassy-net-esp-hosted", features = ["defmt"] } |
| 18 | embassy-net-enc28j60 = { version = "0.1.0", path = "../../embassy-net-enc28j60", features = ["defmt"] } | 18 | embassy-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)] | ||
| 4 | teleprobe_meta::target!(b"nrf52840-dk"); | ||
| 5 | |||
| 6 | use defmt::{assert_eq, *}; | ||
| 7 | use embassy_executor::Spawner; | ||
| 8 | use embassy_nrf::buffered_uarte::{self, BufferedUarte}; | ||
| 9 | use embassy_nrf::{bind_interrupts, peripherals, uarte}; | ||
| 10 | use embedded_io_async::{Read, Write}; | ||
| 11 | use {defmt_rtt as _, panic_probe as _}; | ||
| 12 | |||
| 13 | bind_interrupts!(struct Irqs { | ||
| 14 | UARTE0_UART0 => buffered_uarte::InterruptHandler<peripherals::UARTE0>; | ||
| 15 | }); | ||
| 16 | |||
| 17 | #[embassy_executor::main] | ||
| 18 | async 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 | } | ||
