@@ -11,6 +11,7 @@ use cortex_m::{
11
11
use crate :: {
12
12
pac,
13
13
rcc:: {
14
+ Clocks ,
14
15
ClockSrc ,
15
16
PLLSource ,
16
17
Rcc ,
@@ -67,6 +68,47 @@ impl PWR {
67
68
VcoreRange :: from_bits ( vos)
68
69
}
69
70
71
+ /// Enters low-power run mode
72
+ ///
73
+ /// Please note that there are some restrictions placed on low-power run
74
+ /// mode. Please refer to the STM32L0x2 reference manual, section 6.3.4 for
75
+ /// more information.
76
+ ///
77
+ /// # Panics
78
+ ///
79
+ /// To enter low-power run mode, the system clock frequency should not
80
+ /// exceed the MSI frequency range 1 (131.072 kHz). This method will panic,
81
+ /// if that is the case.
82
+ pub fn enter_low_power_run_mode ( & mut self , clocks : Clocks ) {
83
+ // This follows the procedure laid out in the STM32L0x2 reference
84
+ // manual, section 6.3.4.
85
+
86
+ // Panic, if system clock frequency is outside of allowed range. See
87
+ // STM32L0x1/STM32L0x2/STM32L0x3 reference manuals, sections 6.3.4 and
88
+ // 7.2.3.
89
+ assert ! ( clocks. sys_clk( ) . 0 <= 131_072 ) ;
90
+
91
+ self . switch_vcore_range ( VcoreRange :: Range2 ) ;
92
+
93
+ // First set LPSDSR, then LPRUN, to go into low-power run mode. See
94
+ // STM32L0x2 reference manual, section 6.4.1.
95
+ self . set_lpsdsr ( ) ;
96
+ self . 0 . cr . modify ( |_, w| w. lprun ( ) . set_bit ( ) ) ;
97
+ }
98
+
99
+ /// Exit low-power run mode
100
+ ///
101
+ /// Please note that entering low-power run mode sets Vcore to range 2. This
102
+ /// method will not switch Vcore again, so please make sure to restore the
103
+ /// previous Vcore setting again, if you want to do so. See
104
+ /// [`PWR::switch_vcore_range`]/[`PRW::get_vcore_range`] for more info.
105
+ pub fn exit_low_power_run_mode ( & mut self ) {
106
+ // First reset LPRUN, then LPSDSR. See STM32L0x2 reference manual,
107
+ // section 6.4.1.
108
+ self . 0 . cr . modify ( |_, w| w. lprun ( ) . clear_bit ( ) ) ;
109
+ self . clear_lpsdsr ( ) ;
110
+ }
111
+
70
112
/// Returns a struct that can be used to enter Sleep mode
71
113
pub fn sleep_mode < ' r > ( & ' r mut self , scb : & ' r mut SCB ) -> SleepMode < ' r > {
72
114
SleepMode {
0 commit comments