Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #260 from braun-embedded/dma-cleanup
Clean up DMA code
- Loading branch information
Showing
9 changed files
with
644 additions
and
525 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 {} | ||
} |
Oops, something went wrong.