@@ -15,8 +15,9 @@ use crate::hal::{
1515
1616use cortex_m_rt:: entry;
1717
18+ use bare_metal:: Mutex ;
1819use 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;
2021
2122// A type definition for the GPIO pin to be used for our LED
2223type LEDPIN = gpioa:: PA5 < Output < PushPull > > ;
@@ -35,14 +36,24 @@ fn TIM7() {
3536 static mut INT : Option < Timer < TIM7 > > = None ;
3637
3738 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+
3945 // Move LED pin here, leaving a None in its place
4046 GLED . borrow ( cs) . replace ( None ) . unwrap ( )
4147 } )
4248 } ) ;
4349
4450 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+
4657 // Move LED pin here, leaving a None in its place
4758 GINT . borrow ( cs) . replace ( None ) . unwrap ( )
4859 } )
@@ -55,7 +66,12 @@ fn TIM7() {
5566#[ entry]
5667fn main ( ) -> ! {
5768 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+
5975 let mut rcc = p
6076 . RCC
6177 . configure ( )
@@ -71,7 +87,7 @@ fn main() -> ! {
7187 let led = gpioa. pa5 . into_push_pull_output ( cs) ;
7288
7389 // Move the pin into our global storage
74- * GLED . borrow ( cs) . borrow_mut ( ) = Some ( led) ;
90+ * GLED . borrow ( * cs) . borrow_mut ( ) = Some ( led) ;
7591
7692 // Set up a timer expiring after 1s
7793 let mut timer = Timer :: tim7 ( p. TIM7 , Hertz ( 1 ) , & mut rcc) ;
@@ -80,7 +96,7 @@ fn main() -> ! {
8096 timer. listen ( Event :: TimeOut ) ;
8197
8298 // Move the timer into our global storage
83- * GINT . borrow ( cs) . borrow_mut ( ) = Some ( timer) ;
99+ * GINT . borrow ( * cs) . borrow_mut ( ) = Some ( timer) ;
84100
85101 // Enable TIM7 IRQ, set prio 1 and clear any pending IRQs
86102 let mut nvic = cp. NVIC ;
0 commit comments