5
5
#![ deny( unsafe_code) ]
6
6
#![ allow( non_camel_case_types) ]
7
7
8
- use panic_halt as _;
9
- use nb:: block;
10
8
use core:: cell:: RefCell ;
9
+ use nb:: block;
10
+ use panic_halt as _;
11
11
12
12
use cortex_m:: interrupt:: Mutex ;
13
13
use cortex_m_rt:: entry;
14
14
15
- use stm32f0xx_hal as hal;
16
15
use hal:: {
17
- pac:: { self , interrupt, Interrupt , USART1 } ,
16
+ delay:: Delay ,
17
+ gpio:: {
18
+ gpioa:: { PA15 , PA2 } ,
19
+ gpiob:: PB3 ,
20
+ Alternate , Output , PushPull , AF1 ,
21
+ } ,
22
+ pac:: { self , interrupt, Interrupt , USART1 } ,
18
23
prelude:: * ,
19
- serial:: Serial , gpio:: { gpioa:: { PA2 , PA15 } , Alternate , AF1 , Output , PushPull , gpiob:: PB3 } ,
20
- delay:: Delay
24
+ serial:: Serial ,
21
25
} ;
26
+ use stm32f0xx_hal as hal;
22
27
23
28
// setup some types for our globally shared resources
24
29
type LED_PIN = PB3 < Output < PushPull > > ;
@@ -57,13 +62,16 @@ macro_rules! with_global_mut {
57
62
// a helper macro to generalize the initialization of a UART
58
63
macro_rules! setup_uart {
59
64
( $CS: ident, $DP: ident, $RCC: ident, $GPIOx: ident ) => {
60
- let ( tx, rx) =
61
- (
62
- $GPIOx. pa2. into_alternate_af1( $CS) ,
63
- $GPIOx. pa15. into_alternate_af1( $CS) ,
64
- ) ;
65
-
66
- init_global!( $CS, SER_PORT , Serial :: usart1( $DP. USART1 , ( tx, rx) , 9_600 . bps( ) , & mut $RCC) ) ;
65
+ let ( tx, rx) = (
66
+ $GPIOx. pa2. into_alternate_af1( $CS) ,
67
+ $GPIOx. pa15. into_alternate_af1( $CS) ,
68
+ ) ;
69
+
70
+ init_global!(
71
+ $CS,
72
+ SER_PORT ,
73
+ Serial :: usart1( $DP. USART1 , ( tx, rx) , 9_600 . bps( ) , & mut $RCC)
74
+ ) ;
67
75
with_global_mut!( $CS, SER_PORT , ser, {
68
76
ser. listen( hal:: serial:: Event :: Rxne ) ;
69
77
} ) ;
@@ -89,7 +97,9 @@ fn main() -> ! {
89
97
} ) ;
90
98
91
99
#[ allow( unsafe_code) ] // just this once ;)
92
- unsafe { cortex_m:: peripheral:: NVIC :: unmask ( Interrupt :: USART1 ) ; }
100
+ unsafe {
101
+ cortex_m:: peripheral:: NVIC :: unmask ( Interrupt :: USART1 ) ;
102
+ }
93
103
94
104
loop {
95
105
cortex_m:: interrupt:: free ( |cs| {
@@ -118,4 +128,4 @@ fn USART1() {
118
128
}
119
129
} ) ;
120
130
} ) ;
121
- }
131
+ }
0 commit comments