diff options
| author | Bogdan Petru Chircu Mare <[email protected]> | 2025-11-27 21:39:31 -0800 |
|---|---|---|
| committer | Bogdan Petru Chircu Mare <[email protected]> | 2025-11-28 12:34:37 -0800 |
| commit | 5a6394666e23555e4f329f7b1bd470d0728434a1 (patch) | |
| tree | cf4d3f68d30224051707ff1a74769ff3588e1702 /examples/src/bin/dma_wrap_transfer.rs | |
| parent | 03356a261801d7ee234490809eef3eac3c27cc52 (diff) | |
Updated per PR #52 feedback
Diffstat (limited to 'examples/src/bin/dma_wrap_transfer.rs')
| -rw-r--r-- | examples/src/bin/dma_wrap_transfer.rs | 31 |
1 files changed, 7 insertions, 24 deletions
diff --git a/examples/src/bin/dma_wrap_transfer.rs b/examples/src/bin/dma_wrap_transfer.rs index b115a2c19..8e9aedbfb 100644 --- a/examples/src/bin/dma_wrap_transfer.rs +++ b/examples/src/bin/dma_wrap_transfer.rs | |||
| @@ -4,7 +4,6 @@ | |||
| 4 | //! a source buffer, effectively repeating the source data in the destination. | 4 | //! a source buffer, effectively repeating the source data in the destination. |
| 5 | //! | 5 | //! |
| 6 | //! # Embassy-style features demonstrated: | 6 | //! # Embassy-style features demonstrated: |
| 7 | //! - `dma::edma_tcd()` accessor for simplified register access | ||
| 8 | //! - `DmaChannel::is_done()` and `clear_done()` helper methods | 7 | //! - `DmaChannel::is_done()` and `clear_done()` helper methods |
| 9 | //! - No need to pass register block around | 8 | //! - No need to pass register block around |
| 10 | 9 | ||
| @@ -13,9 +12,8 @@ | |||
| 13 | 12 | ||
| 14 | use embassy_executor::Spawner; | 13 | use embassy_executor::Spawner; |
| 15 | use embassy_mcxa::clocks::config::Div8; | 14 | use embassy_mcxa::clocks::config::Div8; |
| 16 | use embassy_mcxa::clocks::Gate; | 15 | use embassy_mcxa::dma::{DmaChannel, DmaCh0InterruptHandler}; |
| 17 | use embassy_mcxa::dma::{edma_tcd, DmaChannel, DmaCh0InterruptHandler}; | 16 | use embassy_mcxa::bind_interrupts; |
| 18 | use embassy_mcxa::{bind_interrupts, dma}; | ||
| 19 | use embassy_mcxa::lpuart::{Blocking, Config, Lpuart, LpuartTx}; | 17 | use embassy_mcxa::lpuart::{Blocking, Config, Lpuart, LpuartTx}; |
| 20 | use embassy_mcxa::pac; | 18 | use embassy_mcxa::pac; |
| 21 | use {defmt_rtt as _, embassy_mcxa as hal, panic_probe as _}; | 19 | use {defmt_rtt as _, embassy_mcxa as hal, panic_probe as _}; |
| @@ -80,19 +78,7 @@ async fn main(_spawner: Spawner) { | |||
| 80 | 78 | ||
| 81 | defmt::info!("DMA wrap transfer example starting..."); | 79 | defmt::info!("DMA wrap transfer example starting..."); |
| 82 | 80 | ||
| 83 | // Enable DMA0 clock and release reset | 81 | // Enable DMA interrupt (DMA clock/reset/init is handled automatically by HAL) |
| 84 | unsafe { | ||
| 85 | hal::peripherals::DMA0::enable_clock(); | ||
| 86 | hal::peripherals::DMA0::release_reset(); | ||
| 87 | } | ||
| 88 | |||
| 89 | let pac_periphs = unsafe { pac::Peripherals::steal() }; | ||
| 90 | |||
| 91 | unsafe { | ||
| 92 | dma::init(&pac_periphs); | ||
| 93 | } | ||
| 94 | |||
| 95 | // Enable DMA interrupt | ||
| 96 | unsafe { | 82 | unsafe { |
| 97 | cortex_m::peripheral::NVIC::unmask(pac::Interrupt::DMA_CH0); | 83 | cortex_m::peripheral::NVIC::unmask(pac::Interrupt::DMA_CH0); |
| 98 | } | 84 | } |
| @@ -130,9 +116,6 @@ async fn main(_spawner: Spawner) { | |||
| 130 | // Create DMA channel using Embassy-style API | 116 | // Create DMA channel using Embassy-style API |
| 131 | let dma_ch0 = DmaChannel::new(p.DMA_CH0); | 117 | let dma_ch0 = DmaChannel::new(p.DMA_CH0); |
| 132 | 118 | ||
| 133 | // Use edma_tcd() accessor instead of passing register block around | ||
| 134 | let edma = edma_tcd(); | ||
| 135 | |||
| 136 | // Configure wrap transfer using direct TCD access: | 119 | // Configure wrap transfer using direct TCD access: |
| 137 | // SRC is 16 bytes (4 * u32). We want to transfer 32 bytes (8 * u32). | 120 | // SRC is 16 bytes (4 * u32). We want to transfer 32 bytes (8 * u32). |
| 138 | // SRC modulo is 16 bytes (2^4 = 16) - wraps source address. | 121 | // SRC modulo is 16 bytes (2^4 = 16) - wraps source address. |
| @@ -140,7 +123,7 @@ async fn main(_spawner: Spawner) { | |||
| 140 | // This causes the source address to wrap around after 16 bytes, | 123 | // This causes the source address to wrap around after 16 bytes, |
| 141 | // effectively repeating the source data. | 124 | // effectively repeating the source data. |
| 142 | unsafe { | 125 | unsafe { |
| 143 | let t = edma.tcd(0); | 126 | let t = dma_ch0.tcd(); |
| 144 | 127 | ||
| 145 | // Reset channel state | 128 | // Reset channel state |
| 146 | t.ch_csr().write(|w| { | 129 | t.ch_csr().write(|w| { |
| @@ -189,14 +172,14 @@ async fn main(_spawner: Spawner) { | |||
| 189 | cortex_m::asm::dsb(); | 172 | cortex_m::asm::dsb(); |
| 190 | 173 | ||
| 191 | tx.blocking_write(b"Triggering transfer...\r\n").unwrap(); | 174 | tx.blocking_write(b"Triggering transfer...\r\n").unwrap(); |
| 192 | dma_ch0.trigger_start(edma); | 175 | dma_ch0.trigger_start(); |
| 193 | } | 176 | } |
| 194 | 177 | ||
| 195 | // Wait for completion using channel helper method | 178 | // Wait for completion using channel helper method |
| 196 | while !dma_ch0.is_done(edma) { | 179 | while !dma_ch0.is_done() { |
| 197 | cortex_m::asm::nop(); | 180 | cortex_m::asm::nop(); |
| 198 | } | 181 | } |
| 199 | unsafe { dma_ch0.clear_done(edma); } | 182 | unsafe { dma_ch0.clear_done(); } |
| 200 | 183 | ||
| 201 | tx.blocking_write(b"\r\nEDMA wrap transfer example finish.\r\n\r\n") | 184 | tx.blocking_write(b"\r\nEDMA wrap transfer example finish.\r\n\r\n") |
| 202 | .unwrap(); | 185 | .unwrap(); |
