Skip to content

Add DMAMUX support #26

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Aug 11, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions examples/uart-dma.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#![no_main]
#![no_std]

extern crate cortex_m_rt as rt;
extern crate panic_halt;
extern crate stm32g0xx_hal as hal;

use core::fmt::Write;

use hal::prelude::*;
use hal::serial::*;
use hal::stm32;
use hal::dma::{self, Channel, Target};

use rt::entry;

#[entry]
fn main() -> ! {
let dp = stm32::Peripherals::take().expect("cannot take peripherals");
let mut rcc = dp.RCC.constrain();
let gpioa = dp.GPIOA.split(&mut rcc);

let mut usart1 = dp.USART1.usart(
gpioa.pa9,
gpioa.pa10,
FullConfig::default().baudrate(115200.bps()), &mut rcc).unwrap();

writeln!(usart1, "Hello without DMA\r\n").unwrap();

let tx_buffer: [u8; 16] = *b"Hello with DMA!\n";

let (mut tx, _rx) = usart1.split();

let mut dma = dp.DMA.split(&mut rcc, dp.DMAMUX);

let usart = unsafe { &(*stm32::USART1::ptr()) };
let tx_data_register_addr = &usart.tdr as *const _ as u32;
let tx_dma_buf_addr : u32 = tx_buffer.as_ptr() as u32;

dma.ch1.set_direction(dma::Direction::FromMemory);
dma.ch1.set_memory_address(tx_dma_buf_addr, true);
dma.ch1.set_peripheral_address(tx_data_register_addr, false);
dma.ch1.set_transfer_length(tx_buffer.len() as u16);

dma.ch1.select_peripheral(tx.dmamux());

tx.enable_dma();
dma.ch1.enable();

loop {
continue;
}
}
Loading