Skip to content

Commit 835b16c

Browse files
lptim: require PWR_CR.DBP be set
1 parent ea03878 commit 835b16c

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

examples/lptim.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ fn main() -> ! {
4747
let mut led = gpiob.pb2.into_push_pull_output().downgrade();
4848

4949
let mut syscfg = SYSCFG::new(dp.SYSCFG, &mut rcc);
50-
let mut lptim = LpTimer::init_periodic(dp.LPTIM, &mut rcc, ClockSrc::Lse);
50+
let mut lptim = LpTimer::init_periodic(dp.LPTIM, &mut pwr, &mut rcc, ClockSrc::Lse);
5151

5252
let exti_line = 29; // LPTIM1 wakeup
5353

src/lptim.rs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
use crate::hal;
44
use crate::pac::LPTIM;
55
use crate::rcc::Rcc;
6+
use crate::pwr::PWR;
67
use crate::time::{Hertz, MicroSeconds};
78
use cast::{u32, u64};
89
use core::marker::PhantomData;
@@ -90,22 +91,26 @@ impl LpTimer<Periodic> {
9091
/// Initializes the Low-Power Timer in periodic mode.
9192
///
9293
/// The timer needs to be started by calling `.start(freq)`.
93-
pub fn init_periodic(lptim: LPTIM, rcc: &mut Rcc, clk: ClockSrc) -> Self {
94-
Self::init(lptim, rcc, clk)
94+
pub fn init_periodic(lptim: LPTIM, pwr: &mut PWR, rcc: &mut Rcc, clk: ClockSrc) -> Self {
95+
Self::init(lptim, pwr, rcc, clk)
9596
}
9697
}
9798

9899
impl LpTimer<OneShot> {
99100
/// Initializes the Low-Power Timer in one-shot mode.
100101
///
101102
/// The timer needs to be started by calling `.start(freq)`.
102-
pub fn init_oneshot(lptim: LPTIM, rcc: &mut Rcc, clk: ClockSrc) -> Self {
103-
Self::init(lptim, rcc, clk)
103+
pub fn init_oneshot(lptim: LPTIM, pwr: &mut PWR, rcc: &mut Rcc, clk: ClockSrc) -> Self {
104+
Self::init(lptim, pwr, rcc, clk)
104105
}
105106
}
106107

107108
impl<M: CountMode> LpTimer<M> {
108-
fn init(lptim: LPTIM, rcc: &mut Rcc, clk: ClockSrc) -> Self {
109+
fn init(lptim: LPTIM, pwr: &mut PWR, rcc: &mut Rcc, clk: ClockSrc) -> Self {
110+
// `pwr` is not used. It is used as a marker that guarantees that `PWR.CR` is set so this
111+
// function can set the `RCC.LSEON` bit, which is otherwise write protected.
112+
let _ = pwr;
113+
109114
// Enable selected clock and determine its frequency
110115
let input_freq = match clk {
111116
ClockSrc::Apb1 => rcc.clocks.apb1_clk(), // always enabled

0 commit comments

Comments
 (0)