From 990dd5e5db7134193259fcf350c0928b9a64df97 Mon Sep 17 00:00:00 2001 From: Dario Nieuwenhuis Date: Mon, 19 Jun 2023 22:38:27 +0200 Subject: [PATCH 1/2] tests/stm32: do multiple transfers to catch more bugs. --- tests/stm32/src/bin/usart_dma.rs | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/tests/stm32/src/bin/usart_dma.rs b/tests/stm32/src/bin/usart_dma.rs index 50dd2893..c34d9574 100644 --- a/tests/stm32/src/bin/usart_dma.rs +++ b/tests/stm32/src/bin/usart_dma.rs @@ -69,24 +69,27 @@ async fn main(_spawner: Spawner) { const LEN: usize = 128; let mut tx_buf = [0; LEN]; let mut rx_buf = [0; LEN]; - for i in 0..LEN { - tx_buf[i] = i as u8; - } let (mut tx, mut rx) = usart.split(); - let tx_fut = async { - tx.write(&tx_buf).await.unwrap(); - }; - let rx_fut = async { - rx.read(&mut rx_buf).await.unwrap(); - }; + for n in 0..42 { + for i in 0..LEN { + tx_buf[i] = (i ^ n) as u8; + } - // note: rx needs to be polled first, to workaround this bug: - // https://github.com/embassy-rs/embassy/issues/1426 - join(rx_fut, tx_fut).await; + let tx_fut = async { + tx.write(&tx_buf).await.unwrap(); + }; + let rx_fut = async { + rx.read(&mut rx_buf).await.unwrap(); + }; - assert_eq!(tx_buf, rx_buf); + // note: rx needs to be polled first, to workaround this bug: + // https://github.com/embassy-rs/embassy/issues/1426 + join(rx_fut, tx_fut).await; + + assert_eq!(tx_buf, rx_buf); + } info!("Test OK"); cortex_m::asm::bkpt(); From 428a4ba3f98d81de28f8f72115ed6eff5401b46a Mon Sep 17 00:00:00 2001 From: Dario Nieuwenhuis Date: Mon, 19 Jun 2023 22:39:08 +0200 Subject: [PATCH 2/2] stm32/gpdma: clear all interrupts after reset. Reset doesn't clear them, this causes subsequent transfers to instantly complete because the TC flag was set from before. --- embassy-stm32/src/dma/gpdma.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/embassy-stm32/src/dma/gpdma.rs b/embassy-stm32/src/dma/gpdma.rs index c600df92..b7bcf779 100644 --- a/embassy-stm32/src/dma/gpdma.rs +++ b/embassy-stm32/src/dma/gpdma.rs @@ -252,6 +252,7 @@ impl<'a, C: Channel> Transfer<'a, C> { super::dmamux::configure_dmamux(&mut *this.channel, request); ch.cr().write(|w| w.set_reset(true)); + ch.fcr().write(|w| w.0 = 0xFFFF_FFFF); // clear all irqs ch.llr().write(|_| {}); // no linked list ch.tr1().write(|w| { w.set_sdw(data_size.into());