forked from stm32-rs/stm32f1xx-hal
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserial-dma-tx.rs
73 lines (51 loc) · 1.45 KB
/
serial-dma-tx.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
//! Serial interface DMA TX transfer test
#![deny(unsafe_code)]
#![allow(clippy::empty_loop)]
#![no_main]
#![no_std]
use panic_halt as _;
use cortex_m::asm;
use cortex_m_rt::entry;
use stm32f1xx_hal::{
pac,
prelude::*,
serial::{Config, Serial},
};
#[entry]
fn main() -> ! {
let p = pac::Peripherals::take().unwrap();
let mut flash = p.FLASH.constrain();
let rcc = p.RCC.constrain();
let clocks = rcc.cfgr.freeze(&mut flash.acr);
let mut afio = p.AFIO.constrain();
let channels = p.DMA1.split();
let mut gpioa = p.GPIOA.split();
// let mut gpiob = p.GPIOB.split();
// USART1
let tx = gpioa.pa9.into_alternate_push_pull(&mut gpioa.crh);
let rx = gpioa.pa10;
// USART1
// let tx = gpiob.pb6.into_alternate_push_pull(&mut gpiob.crl);
// let rx = gpiob.pb7;
// USART2
// let tx = gpioa.pa2.into_alternate_push_pull(&mut gpioa.crl);
// let rx = gpioa.pa3;
// USART3
// let tx = gpiob.pb10.into_alternate_push_pull(&mut gpiob.crh);
// let rx = gpiob.pb11;
let serial = Serial::new(
p.USART1,
(tx, rx),
&mut afio.mapr,
Config::default().baudrate(9600.bps()),
&clocks,
);
let tx = serial.tx.with_dma(channels.4);
let (_, tx) = tx.write(b"The quick brown fox").wait();
asm::bkpt();
let (_, tx) = tx.write(b" jumps").wait();
asm::bkpt();
tx.write(b" over the lazy dog.").wait();
asm::bkpt();
loop {}
}