diff options
| -rw-r--r-- | embassy-stm32/src/dma/bdma.rs | 7 | ||||
| -rw-r--r-- | embassy-stm32/src/dma/dma.rs | 7 |
2 files changed, 14 insertions, 0 deletions
diff --git a/embassy-stm32/src/dma/bdma.rs b/embassy-stm32/src/dma/bdma.rs index d262caeb6..fbd753a71 100644 --- a/embassy-stm32/src/dma/bdma.rs +++ b/embassy-stm32/src/dma/bdma.rs | |||
| @@ -1,6 +1,7 @@ | |||
| 1 | #![macro_use] | 1 | #![macro_use] |
| 2 | 2 | ||
| 3 | use core::future::Future; | 3 | use core::future::Future; |
| 4 | use core::sync::atomic::{fence, Ordering}; | ||
| 4 | use core::task::Poll; | 5 | use core::task::Poll; |
| 5 | 6 | ||
| 6 | use embassy::interrupt::{Interrupt, InterruptExt}; | 7 | use embassy::interrupt::{Interrupt, InterruptExt}; |
| @@ -61,6 +62,9 @@ pub(crate) unsafe fn do_transfer( | |||
| 61 | 62 | ||
| 62 | // Wait for the transfer to complete when it was ongoing. | 63 | // Wait for the transfer to complete when it was ongoing. |
| 63 | while ch.cr().read().en() {} | 64 | while ch.cr().read().en() {} |
| 65 | |||
| 66 | // "Subsequent reads and writes cannot be moved ahead of preceding reads." | ||
| 67 | fence(Ordering::Acquire); | ||
| 64 | }); | 68 | }); |
| 65 | 69 | ||
| 66 | #[cfg(dmamux)] | 70 | #[cfg(dmamux)] |
| @@ -72,6 +76,9 @@ pub(crate) unsafe fn do_transfer( | |||
| 72 | .modify(|w| w.set_cs(channel_number as _, request)) | 76 | .modify(|w| w.set_cs(channel_number as _, request)) |
| 73 | }); | 77 | }); |
| 74 | 78 | ||
| 79 | // "Preceding reads and writes cannot be moved past subsequent writes." | ||
| 80 | fence(Ordering::Release); | ||
| 81 | |||
| 75 | ch.par().write_value(peri_addr as u32); | 82 | ch.par().write_value(peri_addr as u32); |
| 76 | ch.mar().write_value(mem_addr as u32); | 83 | ch.mar().write_value(mem_addr as u32); |
| 77 | ch.ndtr().write(|w| w.set_ndt(mem_len as u16)); | 84 | ch.ndtr().write(|w| w.set_ndt(mem_len as u16)); |
diff --git a/embassy-stm32/src/dma/dma.rs b/embassy-stm32/src/dma/dma.rs index 9bf083de4..bce9656d1 100644 --- a/embassy-stm32/src/dma/dma.rs +++ b/embassy-stm32/src/dma/dma.rs | |||
| @@ -1,4 +1,5 @@ | |||
| 1 | use core::future::Future; | 1 | use core::future::Future; |
| 2 | use core::sync::atomic::{fence, Ordering}; | ||
| 2 | use core::task::Poll; | 3 | use core::task::Poll; |
| 3 | 4 | ||
| 4 | use embassy::interrupt::{Interrupt, InterruptExt}; | 5 | use embassy::interrupt::{Interrupt, InterruptExt}; |
| @@ -64,11 +65,17 @@ pub(crate) unsafe fn do_transfer( | |||
| 64 | 65 | ||
| 65 | // Wait for the transfer to complete when it was ongoing. | 66 | // Wait for the transfer to complete when it was ongoing. |
| 66 | while ch.cr().read().en() {} | 67 | while ch.cr().read().en() {} |
| 68 | |||
| 69 | // "Subsequent reads and writes cannot be moved ahead of preceding reads." | ||
| 70 | fence(Ordering::Acquire); | ||
| 67 | }); | 71 | }); |
| 68 | 72 | ||
| 69 | #[cfg(dmamux)] | 73 | #[cfg(dmamux)] |
| 70 | super::dmamux::configure_dmamux(dmamux_regs, dmamux_ch_num, request); | 74 | super::dmamux::configure_dmamux(dmamux_regs, dmamux_ch_num, request); |
| 71 | 75 | ||
| 76 | // "Preceding reads and writes cannot be moved past subsequent writes." | ||
| 77 | fence(Ordering::Release); | ||
| 78 | |||
| 72 | unsafe { | 79 | unsafe { |
| 73 | ch.par().write_value(peri_addr as u32); | 80 | ch.par().write_value(peri_addr as u32); |
| 74 | ch.m0ar().write_value(mem_addr as u32); | 81 | ch.m0ar().write_value(mem_addr as u32); |
