Skip to content

Commit

Permalink
Merge pull request #260 from braun-embedded/dma-cleanup
Browse files Browse the repository at this point in the history
Clean up DMA code
  • Loading branch information
hannobraun committed Jul 24, 2020
2 parents fe0adec + 2126a69 commit e1f79c1
Show file tree
Hide file tree
Showing 9 changed files with 644 additions and 525 deletions.
4 changes: 4 additions & 0 deletions Cargo.toml
Expand Up @@ -153,6 +153,10 @@ required-features = ["rt-selected", "82x"]
name = "usart"
required-features = ["rt-selected"]

[[example]]
name = "usart_dma"
required-features = ["rt-selected", "845"]

[[example]]
name = "ctimer_fade"
required-features = ["rt-selected", "845"]
Expand Down
51 changes: 51 additions & 0 deletions examples/usart_dma.rs
@@ -0,0 +1,51 @@
#![no_main]
#![no_std]

extern crate panic_rtt_target;

use lpc8xx_hal::{cortex_m_rt::entry, dma, usart, Peripherals};

#[entry]
fn main() -> ! {
rtt_target::rtt_init_print!();

let p = Peripherals::take().unwrap();

static mut DMA_DESCRIPTOR: dma::DescriptorTable =
dma::DescriptorTable::new();
// Sound, as this is the only place where we do this.
let dma_descriptors = unsafe { &mut DMA_DESCRIPTOR };

let swm = p.SWM.split();
let dma = p.DMA.split(dma_descriptors);
let mut syscon = p.SYSCON.split();

let dma_handle = dma.handle.enable(&mut syscon.handle);
let mut swm_handle = swm.handle.enable(&mut syscon.handle);

let clock_config = usart::Clock::new_with_baudrate(115200);

let (u0_rxd, _) = swm
.movable_functions
.u0_rxd
.assign(p.pins.pio0_24.into_swm_pin(), &mut swm_handle);
let (u0_txd, _) = swm
.movable_functions
.u0_txd
.assign(p.pins.pio0_25.into_swm_pin(), &mut swm_handle);

let serial =
p.USART0
.enable(&clock_config, &mut syscon.handle, u0_rxd, u0_txd);

let channel = dma.channels.channel1.enable(&dma_handle);

serial
.tx
.write_all(b"Hello, world!\r\n", channel)
.wait()
.expect("USART write shouldn't fail");

// We're done. Let's do nothing until someone resets the microcontroller.
loop {}
}

0 comments on commit e1f79c1

Please sign in to comment.