-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathserial-dma-circ.rs
75 lines (55 loc) · 1.79 KB
/
serial-dma-circ.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
74
75
//! Serial interface circular DMA RX transfer test
#![deny(unsafe_code)]
#![no_std]
#![no_main]
use panic_halt as _;
use cortex_m::{asm, singleton};
use cortex_m_rt::entry;
use gd32f1x0_hal::{
dma::Half,
gpio::{OutputMode, PullMode},
pac,
prelude::*,
serial::{Config, Serial},
};
#[entry]
fn main() -> ! {
let p = pac::Peripherals::take().unwrap();
let mut flash = p.fmc.constrain();
let mut rcu = p.rcu.constrain();
let clocks = rcu.cfgr.freeze(&mut flash.ws);
let channels = p.dma.split(&mut rcu.ahb);
let mut gpioa = p.gpioa.split(&mut rcu.ahb);
// let mut gpiob = p.gpiob.split(&mut rcu.ahb);
// USART0
let tx = gpioa
.pa9
.into_alternate(&mut gpioa.config, PullMode::Floating, OutputMode::PushPull);
let rx = gpioa
.pa10
.into_alternate(&mut gpioa.config, PullMode::Floating, OutputMode::PushPull);
// USART1
// let tx = gpioa
// .pa2
// .into_alternate(&mut gpioa.config, PullMode::Floating, OutputMode::PushPull);
// let rx = gpioa
// .pa3
// .into_alternate(&mut gpioa.config, PullMode::Floating, OutputMode::PushPull);
let serial = Serial::usart(
p.usart0,
(tx, rx),
Config::default().baudrate(9_600.bps()),
clocks,
&mut rcu.apb2,
);
let rx = serial.split().1.with_dma(channels.2);
let buf = singleton!(: [[u8; 8]; 2] = [[0; 8]; 2]).unwrap();
let mut circ_buffer = rx.circ_read(buf);
while circ_buffer.readable_half().unwrap() != Half::First {}
let _first_half = circ_buffer.peek(|half, _| *half).unwrap();
while circ_buffer.readable_half().unwrap() != Half::Second {}
let _second_half = circ_buffer.peek(|half, _| *half).unwrap();
asm::bkpt();
#[allow(clippy::empty_loop)]
loop {}
}