aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Gamari <[email protected]>2021-08-31 01:51:49 -0400
committerBen Gamari <[email protected]>2021-09-28 21:19:10 -0400
commit573e6ec373c92e1c85f9d84b3b68f36f1e4d0dc9 (patch)
treec8d3541f3ab88e07cfe9fbc83b4b9a3a3314dd42
parent794798e225cbe9cf690938aaf802ad258dc996e2 (diff)
stm32g0: Add support for low-power run
-rw-r--r--embassy-stm32/src/rcc/g0/mod.rs17
1 files changed, 16 insertions, 1 deletions
diff --git a/embassy-stm32/src/rcc/g0/mod.rs b/embassy-stm32/src/rcc/g0/mod.rs
index 745779175..c0b5b14e3 100644
--- a/embassy-stm32/src/rcc/g0/mod.rs
+++ b/embassy-stm32/src/rcc/g0/mod.rs
@@ -49,7 +49,6 @@ impl Into<u8> for HSI16Prescaler {
49 } 49 }
50} 50}
51 51
52
53impl Into<u8> for APBPrescaler { 52impl Into<u8> for APBPrescaler {
54 fn into(self) -> u8 { 53 fn into(self) -> u8 {
55 match self { 54 match self {
@@ -83,6 +82,7 @@ pub struct Config {
83 mux: ClockSrc, 82 mux: ClockSrc,
84 ahb_pre: AHBPrescaler, 83 ahb_pre: AHBPrescaler,
85 apb_pre: APBPrescaler, 84 apb_pre: APBPrescaler,
85 low_power_run: bool,
86} 86}
87 87
88impl Default for Config { 88impl Default for Config {
@@ -92,6 +92,7 @@ impl Default for Config {
92 mux: ClockSrc::HSI16(HSI16Prescaler::NotDivided), 92 mux: ClockSrc::HSI16(HSI16Prescaler::NotDivided),
93 ahb_pre: AHBPrescaler::NotDivided, 93 ahb_pre: AHBPrescaler::NotDivided,
94 apb_pre: APBPrescaler::NotDivided, 94 apb_pre: APBPrescaler::NotDivided,
95 low_power_run: false,
95 } 96 }
96 } 97 }
97} 98}
@@ -114,6 +115,12 @@ impl Config {
114 self.apb_pre = pre; 115 self.apb_pre = pre;
115 self 116 self
116 } 117 }
118
119 #[inline]
120 pub fn low_power_run(mut self, on: bool) -> Self {
121 self.low_power_run = on;
122 self
123 }
117} 124}
118 125
119/// RCC peripheral 126/// RCC peripheral
@@ -206,6 +213,14 @@ impl RccExt for RCC {
206 } 213 }
207 }; 214 };
208 215
216 let pwr = pac::PWR;
217 if cfgr.low_power_run {
218 assert!(sys_clk.hz() <= 2_000_000.hz());
219 unsafe {
220 pwr.cr1().modify(|w| w.set_lpr(true));
221 }
222 }
223
209 Clocks { 224 Clocks {
210 sys: sys_clk.hz(), 225 sys: sys_clk.hz(),
211 ahb: ahb_freq.hz(), 226 ahb: ahb_freq.hz(),