@@ -16,7 +16,7 @@ use stm32g4xx_hal as hal;
16
16
pub const F_SYS : HertzU32 = HertzU32 :: MHz ( 16 ) ;
17
17
pub const CYCLES_PER_US : u32 = F_SYS . raw ( ) / 1_000_000 ;
18
18
19
- #[ defmt_test :: tests]
19
+ #[ embedded_test :: tests]
20
20
mod tests {
21
21
use embedded_hal:: pwm:: SetDutyCycle ;
22
22
use fixed:: types:: I1F15 ;
@@ -45,9 +45,8 @@ mod tests {
45
45
fn gpio_push_pull ( ) {
46
46
use super :: * ;
47
47
48
- // TODO: Is it ok to steal these?
49
- let cp = unsafe { stm32:: CorePeripherals :: steal ( ) } ;
50
- let dp = unsafe { stm32:: Peripherals :: steal ( ) } ;
48
+ let cp = stm32:: CorePeripherals :: take ( ) . unwrap ( ) ;
49
+ let dp = stm32:: Peripherals :: take ( ) . unwrap ( ) ;
51
50
let mut rcc = dp. RCC . constrain ( ) ;
52
51
let mut delay = cp. SYST . delay ( & rcc. clocks ) ;
53
52
defmt:: dbg!( rcc. clocks. sys_clk) ;
@@ -70,9 +69,8 @@ mod tests {
70
69
fn gpio_open_drain ( ) {
71
70
use super :: * ;
72
71
73
- // TODO: Is it ok to steal these?
74
- let cp = unsafe { stm32:: CorePeripherals :: steal ( ) } ;
75
- let dp = unsafe { stm32:: Peripherals :: steal ( ) } ;
72
+ let cp = stm32:: CorePeripherals :: take ( ) . unwrap ( ) ;
73
+ let dp = stm32:: Peripherals :: take ( ) . unwrap ( ) ;
76
74
let mut rcc = dp. RCC . constrain ( ) ;
77
75
let mut delay = cp. SYST . delay ( & rcc. clocks ) ;
78
76
@@ -102,9 +100,8 @@ mod tests {
102
100
fn pwm ( ) {
103
101
use super :: * ;
104
102
105
- // TODO: Is it ok to steal these?
106
- let mut cp = unsafe { stm32:: CorePeripherals :: steal ( ) } ;
107
- let dp = unsafe { stm32:: Peripherals :: steal ( ) } ;
103
+ let mut cp = stm32:: CorePeripherals :: take ( ) . unwrap ( ) ;
104
+ let dp = stm32:: Peripherals :: take ( ) . unwrap ( ) ;
108
105
let timer = Timer :: enable_timer ( & mut cp) ;
109
106
110
107
let mut rcc = dp. RCC . constrain ( ) ;
@@ -171,7 +168,7 @@ mod tests {
171
168
172
169
use super :: * ;
173
170
174
- let dp = unsafe { stm32:: Peripherals :: steal ( ) } ;
171
+ let dp = stm32:: Peripherals :: take ( ) . unwrap ( ) ;
175
172
let mut rcc = dp. RCC . constrain ( ) ;
176
173
177
174
let mut cordic = dp
@@ -205,9 +202,8 @@ mod tests {
205
202
fn adc ( ) {
206
203
use super :: * ;
207
204
208
- // TODO: Is it ok to steal these?
209
- let cp = unsafe { stm32:: CorePeripherals :: steal ( ) } ;
210
- let dp = unsafe { stm32:: Peripherals :: steal ( ) } ;
205
+ let cp = stm32:: CorePeripherals :: take ( ) . unwrap ( ) ;
206
+ let dp = stm32:: Peripherals :: take ( ) . unwrap ( ) ;
211
207
let mut rcc = dp. RCC . constrain ( ) ;
212
208
let mut delay = cp. SYST . delay ( & rcc. clocks ) ;
213
209
@@ -246,9 +242,8 @@ mod tests {
246
242
dma:: { channel:: DMAExt , config:: DmaConfig , TransferExt } ,
247
243
} ;
248
244
249
- // TODO: Is it ok to steal these?
250
- let cp = unsafe { stm32:: CorePeripherals :: steal ( ) } ;
251
- let dp = unsafe { stm32:: Peripherals :: steal ( ) } ;
245
+ let cp = stm32:: CorePeripherals :: take ( ) . unwrap ( ) ;
246
+ let dp = stm32:: Peripherals :: take ( ) . unwrap ( ) ;
252
247
let mut rcc = dp. RCC . constrain ( ) ;
253
248
let mut delay = cp. SYST . delay ( & rcc. clocks ) ;
254
249
0 commit comments