Skip to main content

ch32_hal/rcc/
shared.rs

1//! Shared RCC helpers used by every family implementation.
2
3use crate::time::Hertz;
4
5use super::Clocks;
6
7/// Update the global [`clocks()`] cache (called from `init` / `refresh`).
8pub(crate) unsafe fn set_clocks(clocks: Clocks) {
9    super::CLOCKS = clocks;
10}
11
12/// APB timer kernel clock (STM32-style ×2 when PPRE ≠ 1).
13pub(crate) fn apb_timer_clk(hclk: Hertz, pclk: Hertz, double_when_divided: bool) -> Hertz {
14    if double_when_divided && hclk != pclk {
15        pclk * 2u32
16    } else {
17        pclk
18    }
19}