From 3e9d5978c088a7d07af63e32a07583f2ff3ae7bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timo=20Kr=C3=B6ger?= Date: Sun, 14 May 2023 21:59:10 +0200 Subject: [PATCH] stm32 uart: Add a test for blocking RX overflow --- tests/stm32/src/bin/usart.rs | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/tests/stm32/src/bin/usart.rs b/tests/stm32/src/bin/usart.rs index bda2ce9c..0749f840 100644 --- a/tests/stm32/src/bin/usart.rs +++ b/tests/stm32/src/bin/usart.rs @@ -8,7 +8,7 @@ use defmt::assert_eq; use embassy_executor::Spawner; use embassy_stm32::dma::NoDma; use embassy_stm32::interrupt; -use embassy_stm32::usart::{Config, Uart}; +use embassy_stm32::usart::{Config, Error, Uart}; use embassy_time::{Duration, Instant}; use example_common::*; @@ -53,6 +53,26 @@ async fn main(_spawner: Spawner) { assert_eq!(buf, data); } + // Test error handling with with an overflow error + { + let config = Config::default(); + let mut usart = Uart::new(&mut usart, &mut rx, &mut tx, &mut irq, NoDma, NoDma, config); + + // Send enough bytes to fill the RX FIFOs off all USART versions. + let data = [0xC0, 0xDE, 0x12, 0x23, 0x34]; + usart.blocking_write(&data).unwrap(); + usart.blocking_flush().unwrap(); + + // The error should be reported first. + let mut buf = [0; 1]; + let err = usart.blocking_read(&mut buf); + assert_eq!(err, Err(Error::Overrun)); + + // At least the first data byte should still be available on all USART versions. + usart.blocking_read(&mut buf).unwrap(); + assert_eq!(buf[0], data[0]); + } + // Test that baudrate divider is calculated correctly. // Do it by comparing the time it takes to send a known number of bytes. for baudrate in [