@@ -15,8 +15,9 @@ use crate::hal::{
15
15
16
16
use cortex_m_rt:: entry;
17
17
18
+ use bare_metal:: Mutex ;
18
19
use core:: cell:: RefCell ;
19
- use cortex_m:: { interrupt :: Mutex , peripheral:: Peripherals as c_m_Peripherals} ;
20
+ use cortex_m:: peripheral:: Peripherals as c_m_Peripherals;
20
21
21
22
// A type definition for the GPIO pin to be used for our LED
22
23
type LEDPIN = gpioa:: PA5 < Output < PushPull > > ;
@@ -35,14 +36,24 @@ fn TIM7() {
35
36
static mut INT : Option < Timer < TIM7 > > = None ;
36
37
37
38
let led = LED . get_or_insert_with ( || {
38
- cortex_m:: interrupt:: free ( |cs| {
39
+ cortex_m:: interrupt:: free ( |_| {
40
+ // SAFETY: We are in a critical section, but the `cortex_m` critical section
41
+ // token is not compatible with the `bare_metal` token. Future version of the
42
+ // `cortex_m` crate will not supply *any* token to this callback!
43
+ let cs = unsafe { bare_metal:: CriticalSection :: new ( ) } ;
44
+
39
45
// Move LED pin here, leaving a None in its place
40
46
GLED . borrow ( cs) . replace ( None ) . unwrap ( )
41
47
} )
42
48
} ) ;
43
49
44
50
let int = INT . get_or_insert_with ( || {
45
- cortex_m:: interrupt:: free ( |cs| {
51
+ cortex_m:: interrupt:: free ( |_| {
52
+ // SAFETY: We are in a critical section, but the `cortex_m` critical section
53
+ // token is not compatible with the `bare_metal` token. Future version of the
54
+ // `cortex_m` crate will not supply *any* token to this callback!
55
+ let cs = unsafe { bare_metal:: CriticalSection :: new ( ) } ;
56
+
46
57
// Move LED pin here, leaving a None in its place
47
58
GINT . borrow ( cs) . replace ( None ) . unwrap ( )
48
59
} )
@@ -55,7 +66,12 @@ fn TIM7() {
55
66
#[ entry]
56
67
fn main ( ) -> ! {
57
68
if let ( Some ( mut p) , Some ( cp) ) = ( Peripherals :: take ( ) , c_m_Peripherals:: take ( ) ) {
58
- cortex_m:: interrupt:: free ( move |cs| {
69
+ cortex_m:: interrupt:: free ( move |_| {
70
+ // SAFETY: We are in a critical section, but the `cortex_m` critical section
71
+ // token is not compatible with the `bare_metal` token. Future version of the
72
+ // `cortex_m` crate will not supply *any* token to this callback!
73
+ let cs = unsafe { & bare_metal:: CriticalSection :: new ( ) } ;
74
+
59
75
let mut rcc = p
60
76
. RCC
61
77
. configure ( )
@@ -71,7 +87,7 @@ fn main() -> ! {
71
87
let led = gpioa. pa5 . into_push_pull_output ( cs) ;
72
88
73
89
// Move the pin into our global storage
74
- * GLED . borrow ( cs) . borrow_mut ( ) = Some ( led) ;
90
+ * GLED . borrow ( * cs) . borrow_mut ( ) = Some ( led) ;
75
91
76
92
// Set up a timer expiring after 1s
77
93
let mut timer = Timer :: tim7 ( p. TIM7 , Hertz ( 1 ) , & mut rcc) ;
@@ -80,7 +96,7 @@ fn main() -> ! {
80
96
timer. listen ( Event :: TimeOut ) ;
81
97
82
98
// Move the timer into our global storage
83
- * GINT . borrow ( cs) . borrow_mut ( ) = Some ( timer) ;
99
+ * GINT . borrow ( * cs) . borrow_mut ( ) = Some ( timer) ;
84
100
85
101
// Enable TIM7 IRQ, set prio 1 and clear any pending IRQs
86
102
let mut nvic = cp. NVIC ;
0 commit comments