aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorDario Nieuwenhuis <[email protected]>2023-05-01 18:17:29 +0200
committerDario Nieuwenhuis <[email protected]>2023-05-01 23:20:51 +0200
commita1d45303c336434929eb8eb7e55629c504a95b0e (patch)
tree3e19fd1bacd3cb2d4276eefc224a81ed6c004ff0 /tests
parent76017796933f0335bcdadbd6b765721833fdacec (diff)
stm32/test: fix race condition in uart_dma.
Diffstat (limited to 'tests')
-rw-r--r--tests/stm32/src/bin/usart_dma.rs27
1 files changed, 18 insertions, 9 deletions
diff --git a/tests/stm32/src/bin/usart_dma.rs b/tests/stm32/src/bin/usart_dma.rs
index d673df0f3..de6cd41d1 100644
--- a/tests/stm32/src/bin/usart_dma.rs
+++ b/tests/stm32/src/bin/usart_dma.rs
@@ -6,6 +6,7 @@
6mod example_common; 6mod example_common;
7use defmt::assert_eq; 7use defmt::assert_eq;
8use embassy_executor::Spawner; 8use embassy_executor::Spawner;
9use embassy_futures::join::join;
9use embassy_stm32::interrupt; 10use embassy_stm32::interrupt;
10use embassy_stm32::usart::{Config, Uart}; 11use embassy_stm32::usart::{Config, Uart};
11use example_common::*; 12use example_common::*;
@@ -76,18 +77,26 @@ async fn main(_spawner: Spawner) {
76 (p.PB6, p.PB7, p.USART1, interrupt::take!(USART1), p.DMA1_CH1, p.DMA1_CH2); 77 (p.PB6, p.PB7, p.USART1, interrupt::take!(USART1), p.DMA1_CH1, p.DMA1_CH2);
77 78
78 let config = Config::default(); 79 let config = Config::default();
79 let mut usart = Uart::new(usart, rx, tx, irq, tx_dma, rx_dma, config); 80 let usart = Uart::new(usart, rx, tx, irq, tx_dma, rx_dma, config);
80 81
81 // We can't send too many bytes, they have to fit in the FIFO. 82 const LEN: usize = 128;
82 // This is because we aren't sending+receiving at the same time. 83 let mut tx_buf = [0; LEN];
83 // For whatever reason, blocking works with 2 bytes but DMA only with 1?? 84 let mut rx_buf = [0; LEN];
85 for i in 0..LEN {
86 tx_buf[i] = i as u8;
87 }
84 88
85 let data = [0x42]; 89 let (mut tx, mut rx) = usart.split();
86 usart.write(&data).await.unwrap();
87 90
88 let mut buf = [0; 1]; 91 let tx_fut = async {
89 usart.read(&mut buf).await.unwrap(); 92 tx.write(&tx_buf).await.unwrap();
90 assert_eq!(buf, data); 93 };
94 let rx_fut = async {
95 rx.read(&mut rx_buf).await.unwrap();
96 };
97 join(rx_fut, tx_fut).await;
98
99 assert_eq!(tx_buf, rx_buf);
91 100
92 info!("Test OK"); 101 info!("Test OK");
93 cortex_m::asm::bkpt(); 102 cortex_m::asm::bkpt();