aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/stm32/src/bin/usart_dma.rs18
1 files changed, 16 insertions, 2 deletions
diff --git a/tests/stm32/src/bin/usart_dma.rs b/tests/stm32/src/bin/usart_dma.rs
index a34498376..9f610739d 100644
--- a/tests/stm32/src/bin/usart_dma.rs
+++ b/tests/stm32/src/bin/usart_dma.rs
@@ -7,7 +7,7 @@ use common::*;
7use defmt::assert_eq; 7use defmt::assert_eq;
8use embassy_executor::Spawner; 8use embassy_executor::Spawner;
9use embassy_futures::join::join; 9use embassy_futures::join::join;
10use embassy_stm32::usart::{Config, Uart}; 10use embassy_stm32::usart::{Config, Error, Uart};
11 11
12#[embassy_executor::main] 12#[embassy_executor::main]
13async fn main(_spawner: Spawner) { 13async fn main(_spawner: Spawner) {
@@ -32,6 +32,7 @@ async fn main(_spawner: Spawner) {
32 32
33 let (mut tx, mut rx) = usart.split(); 33 let (mut tx, mut rx) = usart.split();
34 34
35 let mut noise_count = 0;
35 for n in 0..42 { 36 for n in 0..42 {
36 for i in 0..LEN { 37 for i in 0..LEN {
37 tx_buf[i] = (i ^ n) as u8; 38 tx_buf[i] = (i ^ n) as u8;
@@ -40,17 +41,30 @@ async fn main(_spawner: Spawner) {
40 let tx_fut = async { 41 let tx_fut = async {
41 tx.write(&tx_buf).await.unwrap(); 42 tx.write(&tx_buf).await.unwrap();
42 }; 43 };
44
45 let mut is_noisy = false;
43 let rx_fut = async { 46 let rx_fut = async {
44 rx.read(&mut rx_buf).await.unwrap(); 47 match rx.read(&mut rx_buf).await {
48 Ok(()) => {}
49 Err(Error::Noise) => is_noisy = true,
50 _ => defmt::panic!(),
51 }
45 }; 52 };
46 53
47 // note: rx needs to be polled first, to workaround this bug: 54 // note: rx needs to be polled first, to workaround this bug:
48 // https://github.com/embassy-rs/embassy/issues/1426 55 // https://github.com/embassy-rs/embassy/issues/1426
49 join(rx_fut, tx_fut).await; 56 join(rx_fut, tx_fut).await;
50 57
58 if is_noisy {
59 noise_count += 1;
60 continue;
61 }
62
51 assert_eq!(tx_buf, rx_buf); 63 assert_eq!(tx_buf, rx_buf);
52 } 64 }
53 65
66 defmt::assert!(noise_count < 3);
67
54 // Test flush doesn't hang. Check multiple combinations of async+blocking. 68 // Test flush doesn't hang. Check multiple combinations of async+blocking.
55 tx.write(&tx_buf).await.unwrap(); 69 tx.write(&tx_buf).await.unwrap();
56 tx.flush().await.unwrap(); 70 tx.flush().await.unwrap();