forked from stm32-rs/stm32f7xx-hal
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserial_parity.rs
59 lines (44 loc) · 1.16 KB
/
serial_parity.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
//! Write characters to the serial port with parity.
//!
//! Note: This example is for the STM32F767
#![deny(unsafe_code)]
#![deny(warnings)]
#![no_main]
#![no_std]
extern crate panic_halt;
use nb::block;
use cortex_m_rt::entry;
use stm32f7xx_hal::{
pac,
prelude::*,
serial::{self, Serial, DataBits, Parity},
};
#[entry]
fn main() -> ! {
let p = pac::Peripherals::take().unwrap();
let rcc = p.RCC.constrain();
let clocks = rcc.cfgr.sysclk(48.MHz()).freeze();
let mut delay = p.TIM5.delay_ms(&clocks);
let gpiod = p.GPIOD.split();
let tx = gpiod.pd5.into_alternate();
let rx = gpiod.pd6.into_alternate();
let serial = Serial::new(
p.USART2,
(tx, rx),
&clocks,
serial::Config {
// Using 8 bits of data + 1 for even parity
data_bits: DataBits::Bits9,
parity: Parity::ParityEven,
// Default to 115_200 bauds
..Default::default()
},
);
let (mut tx, mut _rx) = serial.split();
let mut byte: u8 = 0;
loop {
block!(tx.write(byte)).ok();
byte = byte.wrapping_add(1);
delay.delay(10.millis());
}
}