aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorTimo Kröger <[email protected]>2023-05-14 21:59:10 +0200
committerTimo Kröger <[email protected]>2023-05-14 22:03:06 +0200
commit3e9d5978c088a7d07af63e32a07583f2ff3ae7bb (patch)
treeb4b6d24d72d5e9b794911e827a76c86dbb9792e3 /tests
parent977a7906e47ed8b05388e8cdea0403a08a00b962 (diff)
stm32 uart: Add a test for blocking RX overflow
Diffstat (limited to 'tests')
-rw-r--r--tests/stm32/src/bin/usart.rs22
1 files changed, 21 insertions, 1 deletions
diff --git a/tests/stm32/src/bin/usart.rs b/tests/stm32/src/bin/usart.rs
index bda2ce9c2..0749f8406 100644
--- a/tests/stm32/src/bin/usart.rs
+++ b/tests/stm32/src/bin/usart.rs
@@ -8,7 +8,7 @@ use defmt::assert_eq;
8use embassy_executor::Spawner; 8use embassy_executor::Spawner;
9use embassy_stm32::dma::NoDma; 9use embassy_stm32::dma::NoDma;
10use embassy_stm32::interrupt; 10use embassy_stm32::interrupt;
11use embassy_stm32::usart::{Config, Uart}; 11use embassy_stm32::usart::{Config, Error, Uart};
12use embassy_time::{Duration, Instant}; 12use embassy_time::{Duration, Instant};
13use example_common::*; 13use example_common::*;
14 14
@@ -53,6 +53,26 @@ async fn main(_spawner: Spawner) {
53 assert_eq!(buf, data); 53 assert_eq!(buf, data);
54 } 54 }
55 55
56 // Test error handling with with an overflow error
57 {
58 let config = Config::default();
59 let mut usart = Uart::new(&mut usart, &mut rx, &mut tx, &mut irq, NoDma, NoDma, config);
60
61 // Send enough bytes to fill the RX FIFOs off all USART versions.
62 let data = [0xC0, 0xDE, 0x12, 0x23, 0x34];
63 usart.blocking_write(&data).unwrap();
64 usart.blocking_flush().unwrap();
65
66 // The error should be reported first.
67 let mut buf = [0; 1];
68 let err = usart.blocking_read(&mut buf);
69 assert_eq!(err, Err(Error::Overrun));
70
71 // At least the first data byte should still be available on all USART versions.
72 usart.blocking_read(&mut buf).unwrap();
73 assert_eq!(buf[0], data[0]);
74 }
75
56 // Test that baudrate divider is calculated correctly. 76 // Test that baudrate divider is calculated correctly.
57 // Do it by comparing the time it takes to send a known number of bytes. 77 // Do it by comparing the time it takes to send a known number of bytes.
58 for baudrate in [ 78 for baudrate in [