@@ -122,6 +122,22 @@ impl PWR {
122
122
scb,
123
123
}
124
124
}
125
+
126
+ /// Private method to set LPSDSR
127
+ fn set_lpsdsr ( & mut self ) {
128
+ #[ cfg( feature = "stm32l0x1" ) ]
129
+ self . 0 . cr . modify ( |_, w| w. lpsdsr ( ) . low_power_mode ( ) ) ;
130
+ #[ cfg( any( feature = "stm32l0x2" , feature = "stm32l0x3" ) ) ]
131
+ self . 0 . cr . modify ( |_, w| w. lpds ( ) . set_bit ( ) ) ;
132
+ }
133
+
134
+ /// Private method to clear LPSDSR
135
+ fn clear_lpsdsr ( & mut self ) {
136
+ #[ cfg( feature = "stm32l0x1" ) ]
137
+ self . 0 . cr . modify ( |_, w| w. lpsdsr ( ) . main_mode ( ) ) ;
138
+ #[ cfg( any( feature = "stm32l0x2" , feature = "stm32l0x3" ) ) ]
139
+ self . 0 . cr . modify ( |_, w| w. lpds ( ) . clear_bit ( ) ) ;
140
+ }
125
141
}
126
142
127
143
@@ -181,11 +197,7 @@ pub struct SleepMode<'r> {
181
197
182
198
impl PowerMode for SleepMode < ' _ > {
183
199
fn enter ( & mut self ) {
184
- #[ cfg( feature = "stm32l0x1" ) ]
185
- self . pwr . 0 . cr . modify ( |_, w| w. lpsdsr ( ) . main_mode ( ) ) ;
186
- #[ cfg( any( feature = "stm32l0x2" , feature = "stm32l0x3" ) ) ]
187
- self . pwr . 0 . cr . modify ( |_, w| w. lpds ( ) . clear_bit ( ) ) ;
188
-
200
+ self . pwr . clear_lpsdsr ( ) ;
189
201
self . scb . clear_sleepdeep ( ) ;
190
202
191
203
asm:: dsb ( ) ;
@@ -217,11 +229,7 @@ impl PowerMode for LowPowerSleepMode<'_> {
217
229
let old_vcore = self . pwr . get_vcore_range ( ) ;
218
230
self . pwr . switch_vcore_range ( VcoreRange :: Range2 ) ;
219
231
220
- #[ cfg( feature = "stm32l0x1" ) ]
221
- self . pwr . 0 . cr . modify ( |_, w| w. lpsdsr ( ) . low_power_mode ( ) ) ;
222
- #[ cfg( any( feature = "stm32l0x2" , feature = "stm32l0x3" ) ) ]
223
- self . pwr . 0 . cr . modify ( |_, w| w. lpds ( ) . set_bit ( ) ) ;
224
-
232
+ self . pwr . set_lpsdsr ( ) ;
225
233
self . scb . clear_sleepdeep ( ) ;
226
234
227
235
asm:: dsb ( ) ;
0 commit comments