Struct stm32f412g::clocks::Clocks
source · pub struct Clocks<'a, ChipSpecs> {
pub hsi: Hsi<'a>,
pub hse: Hse<'a>,
pub pll: Pll<'a, ChipSpecs>,
/* private fields */
}
Expand description
Main struct for configuring on-board clocks.
Fields§
§hsi: Hsi<'a>
High speed internal clock
hse: Hse<'a>
High speed external clock
pll: Pll<'a, ChipSpecs>
Main phase loop-lock clock
Implementations§
source§impl<'a, ChipSpecs> Clocks<'a, ChipSpecs>where
ChipSpecs: ChipSpecs,
impl<'a, ChipSpecs> Clocks<'a, ChipSpecs>where
ChipSpecs: ChipSpecs,
pub fn new(rcc: &'a Rcc) -> Clocks<'a, ChipSpecs>
sourcepub fn set_ahb_prescaler(
&self,
prescaler: AHBPrescaler,
) -> Result<(), ErrorCode>
pub fn set_ahb_prescaler( &self, prescaler: AHBPrescaler, ) -> Result<(), ErrorCode>
Set the AHB prescaler
AHB bus, core, memory, DMA, Cortex System timer and FCLK Cortex free-running clock frequencies are equal to the system clock frequency divided by the AHB prescaler.
§Errors:
- Err(ErrorCode::FAIL) if changing the AHB prescaler doesn’t preserve APB frequency constraints
- Err(ErrorCode::BUSY) if changing the AHB prescaler took too long. Retry.
sourcepub fn get_ahb_prescaler(&self) -> AHBPrescaler
pub fn get_ahb_prescaler(&self) -> AHBPrescaler
Get the current configured AHB prescaler
sourcepub fn get_ahb_frequency_mhz(&self) -> usize
pub fn get_ahb_frequency_mhz(&self) -> usize
Get the frequency of the AHB
sourcepub fn set_apb1_prescaler(
&self,
prescaler: APBPrescaler,
) -> Result<(), ErrorCode>
pub fn set_apb1_prescaler( &self, prescaler: APBPrescaler, ) -> Result<(), ErrorCode>
Set the APB1 prescaler.
The APB1 peripheral clock frequency is equal to the AHB frequency divided by the APB1 prescaler.
§Errors:
- Err(ErrorCode::FAIL) if the desired prescaler would break the APB1 frequency limit
- Err(ErrorCode::BUSY) if setting the prescaler took too long. Retry.
sourcepub fn get_apb1_prescaler(&self) -> APBPrescaler
pub fn get_apb1_prescaler(&self) -> APBPrescaler
Get the current configured APB1 prescaler
sourcepub fn get_apb1_frequency_mhz(&self) -> usize
pub fn get_apb1_frequency_mhz(&self) -> usize
Get the current APB1 frequency
sourcepub fn set_apb2_prescaler(
&self,
prescaler: APBPrescaler,
) -> Result<(), ErrorCode>
pub fn set_apb2_prescaler( &self, prescaler: APBPrescaler, ) -> Result<(), ErrorCode>
Set the APB2 prescaler.
The APB2 peripheral clock frequency is equal to the AHB frequency divided by the APB2 prescaler.
§Errors:
- Err(ErrorCode::FAIL) if the desired prescaler would break the APB2 frequency limit
- Err(ErrorCode::BUSY) if setting the prescaler took too long. Retry.
sourcepub fn get_apb2_prescaler(&self) -> APBPrescaler
pub fn get_apb2_prescaler(&self) -> APBPrescaler
Get the current configured APB2 prescaler
sourcepub fn get_apb2_frequency_mhz(&self) -> usize
pub fn get_apb2_frequency_mhz(&self) -> usize
Get the current APB2 frequency
sourcepub fn set_sys_clock_source(
&self,
source: SysClockSource,
) -> Result<(), ErrorCode>
pub fn set_sys_clock_source( &self, source: SysClockSource, ) -> Result<(), ErrorCode>
Set the system clock source
§Errors:
- Err(ErrorCode::FAIL) if the source is not enabled.
- Err(ErrorCode::SIZE) if the source frequency surpasses the system clock frequency limit, or the APB1 and APB2 limits are not satisfied.
- Err(ErrorCode::BUSY) if the source switching took too long. Retry.
sourcepub fn get_sys_clock_source(&self) -> SysClockSource
pub fn get_sys_clock_source(&self) -> SysClockSource
Get the current system clock source
sourcepub fn get_sys_clock_frequency_mhz(&self) -> usize
pub fn get_sys_clock_frequency_mhz(&self) -> usize
Get the current system clock frequency in MHz
sourcepub fn _get_sys_clock_frequency_mhz_no_cache(&self) -> usize
pub fn _get_sys_clock_frequency_mhz_no_cache(&self) -> usize
Get the current system clock frequency in MHz from RCC registers instead of the cached value. Used for debug only.
sourcepub fn set_pll_frequency_mhz(
&self,
pll_source: PllSource,
desired_frequency_mhz: usize,
) -> Result<(), ErrorCode>
pub fn set_pll_frequency_mhz( &self, pll_source: PllSource, desired_frequency_mhz: usize, ) -> Result<(), ErrorCode>
Set the frequency of the PLL clock.
§Parameters
-
pll_source: PLL source clock (HSI or HSE)
-
desired_frequency_mhz: the desired frequency in MHz. Supported values: 24-216MHz for STM32F401 and 13-216MHz for all the other chips
§Errors
- Err(ErrorCode::INVAL): if the desired frequency can’t be achieved
- Err(ErrorCode::FAIL): if the PLL clock is already enabled. It must be disabled before
sourcepub fn set_mco1_clock_source(&self, source: MCO1Source) -> Result<(), ErrorCode>
pub fn set_mco1_clock_source(&self, source: MCO1Source) -> Result<(), ErrorCode>
Set the clock source for the microcontroller clock output 1 (MCO1)
§Errors:
- Err(ErrorCode::FAIL) if the source apart from HSI is already enabled.
sourcepub fn get_mco1_clock_source(&self) -> MCO1Source
pub fn get_mco1_clock_source(&self) -> MCO1Source
Get the clock source of the MCO1
sourcepub fn set_mco1_clock_divider(
&self,
divider: MCO1Divider,
) -> Result<(), ErrorCode>
pub fn set_mco1_clock_divider( &self, divider: MCO1Divider, ) -> Result<(), ErrorCode>
Set MCO1 divider
§Errors:
- Err(ErrorCode::FAIL) if the configured source apart from HSI is already enabled.
sourcepub fn get_mco1_clock_divider(&self) -> MCO1Divider
pub fn get_mco1_clock_divider(&self) -> MCO1Divider
Get MCO1 divider