File tree Expand file tree Collapse file tree 2 files changed +59
-0
lines changed Expand file tree Collapse file tree 2 files changed +59
-0
lines changed Original file line number Diff line number Diff line change @@ -154,6 +154,10 @@ required-features = ["stm32f746", "rt"]
154
154
name = " serial_echo"
155
155
required-features = [" stm32f746" , " rt" ]
156
156
157
+ [[example ]]
158
+ name = " serial_parity"
159
+ required-features = [" stm32f767" , " rt" ]
160
+
157
161
[[example ]]
158
162
name = " stm32f7disco-screen"
159
163
required-features = [" stm32f746" , " rt" ]
Original file line number Diff line number Diff line change
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
+ }
You can’t perform that action at this time.
0 commit comments