Skip to content

Commit 38d11c2

Browse files
authored
timer: delay: correct clock sources for SYST (#120)
1 parent 306aa0a commit 38d11c2

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

src/timer/delay.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//! Delays
22
use core::cmp;
3-
use cortex_m::peripheral::SYST;
3+
use cortex_m::peripheral::{syst::SystClkSource, SYST};
44
use fugit::ExtU32;
55
use hal::blocking::delay::{DelayMs, DelayUs};
66

@@ -20,11 +20,12 @@ pub trait DelayExt<TIM> {
2020

2121
impl Delay<SYST> {
2222
/// Configures the system timer (SysTick) as a delay provider
23-
pub fn syst(syst: SYST, rcc: &Rcc) -> Self {
24-
Delay {
25-
tim: syst,
26-
clk: rcc.clocks.core_clk,
27-
}
23+
pub fn syst(mut syst: SYST, rcc: &Rcc) -> Self {
24+
let clk = match syst.get_clock_source() {
25+
SystClkSource::Core => rcc.clocks.ahb_clk,
26+
SystClkSource::External => rcc.clocks.core_clk,
27+
};
28+
Delay { tim: syst, clk }
2829
}
2930

3031
pub fn delay(&mut self, delay: MicroSecond) {

0 commit comments

Comments
 (0)