Skip to content

Commit 69ecdf3

Browse files
ahdinosaurmaximeborges
authored andcommitted
add serial parity example
1 parent 10007a1 commit 69ecdf3

File tree

2 files changed

+59
-0
lines changed

2 files changed

+59
-0
lines changed

Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,10 @@ required-features = ["stm32f746", "rt"]
154154
name = "serial_echo"
155155
required-features = ["stm32f746", "rt"]
156156

157+
[[example]]
158+
name = "serial_parity"
159+
required-features = ["stm32f767", "rt"]
160+
157161
[[example]]
158162
name = "stm32f7disco-screen"
159163
required-features = ["stm32f746", "rt"]

examples/serial_parity.rs

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
//! Write characters to the serial port with parity.
2+
//!
3+
//! Note: This example is for the STM32F767
4+
5+
#![deny(unsafe_code)]
6+
#![deny(warnings)]
7+
#![no_main]
8+
#![no_std]
9+
10+
extern crate panic_halt;
11+
12+
use nb::block;
13+
14+
use cortex_m_rt::entry;
15+
use stm32f7xx_hal::{
16+
pac,
17+
prelude::*,
18+
serial::{self, Serial},
19+
};
20+
21+
#[entry]
22+
fn main() -> ! {
23+
let p = pac::Peripherals::take().unwrap();
24+
25+
let rcc = p.RCC.constrain();
26+
let clocks = rcc.cfgr.sysclk(216_000_000.Hz()).freeze();
27+
28+
let gpiod = p.GPIOD.split();
29+
30+
let tx = gpiod.pd5.into_alternate();
31+
let rx = gpiod.pd6.into_alternate();
32+
33+
let serial = Serial::new(
34+
p.USART2,
35+
(tx, rx),
36+
&clocks,
37+
serial::Config {
38+
baud_rate: 56_700.bps(),
39+
oversampling: serial::Oversampling::By16,
40+
character_match: None,
41+
sysclock: false,
42+
parity: serial::Parity::ParityEven,
43+
},
44+
);
45+
46+
let (mut tx, mut _rx) = serial.split();
47+
48+
let mut byte: u8 = 0;
49+
50+
loop {
51+
block!(tx.write(byte)).ok();
52+
53+
byte += 1;
54+
}
55+
}

0 commit comments

Comments
 (0)