|
6 | 6 | mod example_common;
|
7 | 7 | use defmt::assert_eq;
|
8 | 8 | use embassy_executor::Spawner;
|
| 9 | +use embassy_futures::join::join; |
9 | 10 | use embassy_stm32::interrupt;
|
10 | 11 | use embassy_stm32::usart::{Config, Uart};
|
11 | 12 | use example_common::*;
|
@@ -76,18 +77,26 @@ async fn main(_spawner: Spawner) {
|
76 | 77 | (p.PB6, p.PB7, p.USART1, interrupt::take!(USART1), p.DMA1_CH1, p.DMA1_CH2);
|
77 | 78 |
|
78 | 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 |
| - // This is because we aren't sending+receiving at the same time. |
83 |
| - // For whatever reason, blocking works with 2 bytes but DMA only with 1?? |
| 82 | + const LEN: usize = 128; |
| 83 | + let mut tx_buf = [0; LEN]; |
| 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]; |
86 |
| - usart.write(&data).await.unwrap(); |
| 89 | + let (mut tx, mut rx) = usart.split(); |
87 | 90 |
|
88 |
| - let mut buf = [0; 1]; |
89 |
| - usart.read(&mut buf).await.unwrap(); |
90 |
| - assert_eq!(buf, data); |
| 91 | + let tx_fut = async { |
| 92 | + tx.write(&tx_buf).await.unwrap(); |
| 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 | 101 | info!("Test OK");
|
93 | 102 | cortex_m::asm::bkpt();
|
|
0 commit comments