aboutsummaryrefslogtreecommitdiff
path: root/tests/stm32/src/bin
diff options
context:
space:
mode:
Diffstat (limited to 'tests/stm32/src/bin')
-rw-r--r--tests/stm32/src/bin/usart.rs44
1 files changed, 32 insertions, 12 deletions
diff --git a/tests/stm32/src/bin/usart.rs b/tests/stm32/src/bin/usart.rs
index 0b98d3eeb..ef7efe96a 100644
--- a/tests/stm32/src/bin/usart.rs
+++ b/tests/stm32/src/bin/usart.rs
@@ -6,6 +6,7 @@ mod common;
6use common::*; 6use common::*;
7use defmt::{assert, assert_eq, unreachable}; 7use defmt::{assert, assert_eq, unreachable};
8use embassy_executor::Spawner; 8use embassy_executor::Spawner;
9use embassy_stm32::mode::Blocking;
9use embassy_stm32::usart::{Config, ConfigError, Error, Uart}; 10use embassy_stm32::usart::{Config, ConfigError, Error, Uart};
10use embassy_time::{Duration, Instant, block_for}; 11use embassy_time::{Duration, Instant, block_for};
11 12
@@ -24,22 +25,41 @@ async fn main(_spawner: Spawner) {
24 let config = Config::default(); 25 let config = Config::default();
25 let mut usart = Uart::new_blocking(usart.reborrow(), rx.reborrow(), tx.reborrow(), config).unwrap(); 26 let mut usart = Uart::new_blocking(usart.reborrow(), rx.reborrow(), tx.reborrow(), config).unwrap();
26 27
27 // We can't send too many bytes, they have to fit in the FIFO. 28 let test_usart = async |usart: &mut Uart<'_, Blocking>| -> Result<(), Error> {
28 // This is because we aren't sending+receiving at the same time. 29 // We can't send too many bytes, they have to fit in the FIFO.
30 // This is because we aren't sending+receiving at the same time.
29 31
30 let data = [0xC0, 0xDE]; 32 let data = [0xC0, 0xDE];
31 usart.blocking_write(&data).unwrap(); 33 usart.blocking_write(&data)?;
32 34
33 let mut buf = [0; 2]; 35 let mut buf = [0; 2];
34 usart.blocking_read(&mut buf).unwrap(); 36 usart.blocking_read(&mut buf)?;
35 assert_eq!(buf, data); 37 assert_eq!(buf, data);
36 38
37 // Test flush doesn't hang. 39 // Test flush doesn't hang.
38 usart.blocking_write(&data).unwrap(); 40 usart.blocking_write(&data)?;
39 usart.blocking_flush().unwrap(); 41 usart.blocking_flush()?;
40 42
41 // Test flush doesn't hang if there's nothing to flush 43 // Test flush doesn't hang if there's nothing to flush
42 usart.blocking_flush().unwrap(); 44 usart.blocking_flush()?;
45
46 Ok(())
47 };
48
49 let mut is_ok = false;
50 for _ in 0..3 {
51 match test_usart(&mut usart).await {
52 Ok(()) => is_ok = true,
53 Err(Error::Noise) => is_ok = false,
54 Err(e) => defmt::panic!("{}", e),
55 }
56
57 if is_ok {
58 break;
59 }
60 }
61
62 assert!(is_ok);
43 } 63 }
44 64
45 // Test error handling with with an overflow error 65 // Test error handling with with an overflow error