Skip to content

Commit 242741b

Browse files
committed
Same clear of ok flag and wait for it for CMP set
1 parent 01369e9 commit 242741b

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/lptimer.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ macro_rules! hal {
138138
/// has to be used _after_ enabling of lptim
139139
#[inline(always)]
140140
fn set_arr(&mut self, arr_value: u16) {
141-
// clear autoreload register OK interrupf flag
141+
// clear autoreload register OK interrupt flag
142142
self.lptim.icr.write(|w| w.arrokcf().set_bit());
143143

144144
// Write autoreload value
@@ -273,9 +273,15 @@ macro_rules! hal {
273273
/// Set the compare match field for this LowPowerTimer
274274
#[inline]
275275
pub fn set_compare_match(&mut self, value: u16) {
276+
// clear compare register update ok flag
277+
self.lptim.icr.write(|w| w.cmpokcf().set_bit());
278+
276279
// This operation is sound as compare_value is a u16, and there are 16 writeable bits
277280
// Additionally, the LPTIM peripheral will always be in the enabled state when this code is called
278281
self.lptim.cmp.write(|w| unsafe { w.bits(value as u32) });
282+
283+
// wait for compare register update ok interrupt to be signalled (RM0394 Rev 4, sec. 30.7.1, Bit 4)
284+
while self.lptim.isr.read().cmpok().bit_is_clear() {}
279285
}
280286

281287
/// Get the current counter value for this LowPowerTimer

0 commit comments

Comments
 (0)