diff options
| author | xoviat <[email protected]> | 2025-12-08 09:26:55 -0600 |
|---|---|---|
| committer | xoviat <[email protected]> | 2025-12-08 09:26:55 -0600 |
| commit | f6b9c1ddaffeab5f22db5552711ceb5a595d2e3a (patch) | |
| tree | cda4d0e0eb693502184b0ee9ca7d74044fa5b1e2 /tests | |
| parent | 0d8255481498a5d5d78c046f0edee396a74fd7c9 (diff) | |
stm32/tests: allow some noise
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/stm32/src/bin/usart_dma.rs | 18 |
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::*; | |||
| 7 | use defmt::assert_eq; | 7 | use defmt::assert_eq; |
| 8 | use embassy_executor::Spawner; | 8 | use embassy_executor::Spawner; |
| 9 | use embassy_futures::join::join; | 9 | use embassy_futures::join::join; |
| 10 | use embassy_stm32::usart::{Config, Uart}; | 10 | use embassy_stm32::usart::{Config, Error, Uart}; |
| 11 | 11 | ||
| 12 | #[embassy_executor::main] | 12 | #[embassy_executor::main] |
| 13 | async fn main(_spawner: Spawner) { | 13 | async 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(); |
