stm32g0: Add support for low-power run
This commit is contained in:
parent
794798e225
commit
573e6ec373
1 changed files with 16 additions and 1 deletions
|
@ -49,7 +49,6 @@ impl Into<u8> for HSI16Prescaler {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
impl Into<u8> for APBPrescaler {
|
||||
fn into(self) -> u8 {
|
||||
match self {
|
||||
|
@ -83,6 +82,7 @@ pub struct Config {
|
|||
mux: ClockSrc,
|
||||
ahb_pre: AHBPrescaler,
|
||||
apb_pre: APBPrescaler,
|
||||
low_power_run: bool,
|
||||
}
|
||||
|
||||
impl Default for Config {
|
||||
|
@ -92,6 +92,7 @@ impl Default for Config {
|
|||
mux: ClockSrc::HSI16(HSI16Prescaler::NotDivided),
|
||||
ahb_pre: AHBPrescaler::NotDivided,
|
||||
apb_pre: APBPrescaler::NotDivided,
|
||||
low_power_run: false,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -114,6 +115,12 @@ impl Config {
|
|||
self.apb_pre = pre;
|
||||
self
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn low_power_run(mut self, on: bool) -> Self {
|
||||
self.low_power_run = on;
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
/// RCC peripheral
|
||||
|
@ -206,6 +213,14 @@ impl RccExt for RCC {
|
|||
}
|
||||
};
|
||||
|
||||
let pwr = pac::PWR;
|
||||
if cfgr.low_power_run {
|
||||
assert!(sys_clk.hz() <= 2_000_000.hz());
|
||||
unsafe {
|
||||
pwr.cr1().modify(|w| w.set_lpr(true));
|
||||
}
|
||||
}
|
||||
|
||||
Clocks {
|
||||
sys: sys_clk.hz(),
|
||||
ahb: ahb_freq.hz(),
|
||||
|
|
Loading…
Reference in a new issue