diff options
| -rw-r--r-- | tests/stm32/src/bin/usart_dma.rs | 27 |
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 @@ | |||
| 6 | mod example_common; | 6 | mod example_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_stm32::interrupt; | 10 | use embassy_stm32::interrupt; |
| 10 | use embassy_stm32::usart::{Config, Uart}; | 11 | use embassy_stm32::usart::{Config, Uart}; |
| 11 | use example_common::*; | 12 | use 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(); |
