Skip to main content

RCC MCAL Module

Supported STM32 families: F4 · G4 · H5 · U5
Not supported: H7, L4

This module provides an abstraction layer for the Reset and Clock Control (RCC) peripheral on STM32 microcontrollers.
It is part of the MCAL (Microcontroller Abstraction Layer) and allows safe and portable configuration of system clocks, PLLs, peripheral clocks, low-power states, and reset management.


Features​

  • Module initialization and de-initialization
  • Peripheral clock enable/disable and state management
  • Peripheral reset handling
  • Power and sleep state configuration
  • PLL configuration and management
  • Clock sources configuration (HSE, HSI16, HSI48, MSI, LSE, LSI)
  • RTC clock source selection
  • System clock and bus clock dividers
  • Flash latency and prefetch control
  • SysTick interval configuration

Public API​

Module Management​

  • rcc_ModuleVersion_t Rcc_Get_ModuleVersion(void)
  • rcc_RequestState_t Rcc_Init(rcc_ConfigStruct_t * const clockConfig)
  • void Rcc_Deinit(rcc_ConfigStruct_t * const clockConfig)
  • void Rcc_Task(void)
  • rcc_RequestState_t Rcc_Get_DefaultConfig(rcc_ConfigStruct_t * const clockConfig)

Peripheral Clock Management​

  • rcc_RequestState_t Rcc_Set_PeriphActive(rcc_PeriphId_t periphId)
  • rcc_RequestState_t Rcc_Set_PeriphInactive(rcc_PeriphId_t periphId)
  • rcc_RequestState_t Rcc_Get_PeriphState(rcc_PeriphId_t periphId, rcc_FunctionState_t * const funcState)
  • rcc_RequestState_t Rcc_Get_PeriphClk(rcc_PeriphId_t periphId, rcc_FreqHz_t * const periphClk)

Peripheral Reset Management​

  • rcc_RequestState_t Rcc_Set_ResetActive(rcc_PeriphId_t periphId)
  • rcc_RequestState_t Rcc_Set_ResetInactive(rcc_PeriphId_t periphId)
  • rcc_RequestState_t Rcc_Get_ResetState(rcc_PeriphId_t periphId, rcc_FunctionState_t * const funcState)

Power and Sleep Management​

  • rcc_RequestState_t Rcc_Set_SleepActive(rcc_PeriphId_t periphId)
  • rcc_RequestState_t Rcc_Set_SleepInactive(rcc_PeriphId_t periphId)
  • rcc_RequestState_t Rcc_Get_SleepState(rcc_PeriphId_t periphId, rcc_FunctionState_t * const funcState)

PLL Configuration​

  • rcc_RequestState_t Rcc_Set_PllConfig(rcc_PllId_t pllId, rcc_PllConfigStruct_t * const configStruct)
  • rcc_RequestState_t Rcc_Get_PllInternalClk(rcc_PllId_t pllId, rcc_FreqHz_t * const pllClk)
  • rcc_RequestState_t Rcc_Set_PllActive(rcc_PllId_t pllId)
  • rcc_RequestState_t Rcc_Set_PllInactive(rcc_PllId_t pllId)
  • rcc_RequestState_t Rcc_Get_PllState(rcc_PllId_t pllId, rcc_FunctionState_t * const retState)
  • rcc_RequestState_t Rcc_Set_PllsSource(rcc_PllId_t pllId, rcc_PllClkSrc_t clkSource)
  • rcc_RequestState_t Rcc_Get_PllsSource(rcc_PllId_t pllId, rcc_PllClkSrc_t * const clkSource)
  • rcc_RequestState_t Rcc_Get_PllClk_OutP(rcc_PllId_t pllId, rcc_FreqHz_t *pllClk)
  • rcc_RequestState_t Rcc_Get_PllClk_OutQ(rcc_PllId_t pllId, rcc_FreqHz_t *pllClk)
  • rcc_RequestState_t Rcc_Get_PllClk_OutR(rcc_PllId_t pllId, rcc_FreqHz_t *pllClk)

Clock Sources​

  • rcc_RequestState_t Rcc_Set_HseActive(rcc_HseType_t hseType)
  • rcc_RequestState_t Rcc_Set_HseInactive(void)
  • rcc_RequestState_t Rcc_Get_HseState(rcc_FunctionState_t * const retState)
  • rcc_RequestState_t Rcc_Set_HseClk(rcc_FreqHz_t hseFreq)
  • rcc_RequestState_t Rcc_Get_HseClk(rcc_FreqHz_t * const hseFreq)
  • rcc_RequestState_t Rcc_Set_Hsi16Active(void)
  • rcc_RequestState_t Rcc_Set_Hsi16Inactive(void)
  • rcc_RequestState_t Rcc_Get_Hsi16State(rcc_FunctionState_t * const retState)
  • rcc_RequestState_t Rcc_Get_Hsi16Clk(rcc_FreqHz_t * const hsiClk)
  • rcc_RequestState_t Rcc_Set_Hsi48Active(void)
  • rcc_RequestState_t Rcc_Set_Hsi48Inactive(void)
  • rcc_RequestState_t Rcc_Get_Hsi48State(rcc_FunctionState_t * const retState)
  • rcc_RequestState_t Rcc_Get_Hsi48Clk(rcc_FreqHz_t * const hsiClk)
  • rcc_RequestState_t Rcc_Set_MsisActive(rcc_MsisOutId_t msisId, rcc_MsisClkFreq_t clkFreq)
  • rcc_RequestState_t Rcc_Set_MsisInactive(rcc_MsisOutId_t msisId)
  • rcc_RequestState_t Rcc_Get_MsisState(rcc_MsisOutId_t msisId, rcc_FunctionState_t * const retState)
  • rcc_RequestState_t Rcc_Get_MsisClk(rcc_MsisOutId_t msisId, rcc_FreqHz_t * const msiClk)

Low-Speed Clock Sources​

  • rcc_RequestState_t Rcc_Set_LseActive(void)
  • rcc_RequestState_t Rcc_Set_LseInactive(void)
  • rcc_RequestState_t Rcc_Get_LseState(rcc_FunctionState_t * const retState)
  • rcc_RequestState_t Rcc_Get_LseClk(rcc_FreqHz_t * const lseClk)
  • rcc_RequestState_t Rcc_Set_LsiActive(void)
  • rcc_RequestState_t Rcc_Set_LsiInactive(void)
  • rcc_RequestState_t Rcc_Get_LsiState(rcc_FunctionState_t * const retState)
  • rcc_RequestState_t Rcc_Get_LsiClk(rcc_FreqHz_t * const lsiClk)
  • rcc_RequestState_t Rcc_Set_RtcClkSource(rcc_Rtc_ClkSource_t clkSource)
  • rcc_RequestState_t Rcc_Get_RtcClkSource(rcc_Rtc_ClkSource_t * const clkSource)

Clock Bus Configuration​

  • rcc_RequestState_t Rcc_Set_SysClkSource(rcc_SystemClkSrc_t systemClkSource)
  • rcc_RequestState_t Rcc_Get_SysClkSource(rcc_SystemClkSrc_t * const systemClkSource)
  • rcc_RequestState_t Rcc_Get_SysClk(rcc_FreqHz_t * const busClk)
  • rcc_RequestState_t Rcc_Set_AHBDivider(rcc_AHB_Div_t dividerId)
  • rcc_RequestState_t Rcc_Get_AHBDivider(rcc_AHB_Div_t * const dividerId)
  • rcc_RequestState_t Rcc_Get_AHBClk(rcc_FreqHz_t * const busClk)
  • rcc_RequestState_t Rcc_Set_APB1Divider(rcc_APB1_Div_t dividerId)
  • rcc_RequestState_t Rcc_Get_APB1Divider(rcc_APB1_Div_t * const dividerId)
  • rcc_RequestState_t Rcc_Get_APB1Clk(rcc_FreqHz_t * const busClk)
  • rcc_RequestState_t Rcc_Set_APB2Divider(rcc_APB2_Div_t dividerId)
  • rcc_RequestState_t Rcc_Get_APB2Divider(rcc_APB2_Div_t * const dividerId)
  • rcc_RequestState_t Rcc_Get_APB2Clk(rcc_FreqHz_t * const busClk)
  • rcc_RequestState_t Rcc_Set_APB3Divider(rcc_APB3_Div_t dividerId)
  • rcc_RequestState_t Rcc_Get_APB3Divider(rcc_APB3_Div_t * const dividerId)
  • rcc_RequestState_t Rcc_Get_APB3Clk(rcc_FreqHz_t * const busClk)

Flash and System Configuration​

  • rcc_RequestState_t Rcc_Set_PwrRange(rcc_ConfigStruct_t * const clockConfig)
  • rcc_RequestState_t Rcc_Set_FlashLatency(rcc_ConfigStruct_t * const clockConfig)
  • rcc_RequestState_t Rcc_Set_FlashPrefetchActive(void)
  • rcc_RequestState_t Rcc_Set_FlashPrefetchInactive(void)
  • rcc_RequestState_t Rcc_Set_SysTickInterval(rcc_Time_ms_t sysTickInterval)
  • rcc_RequestState_t Rcc_Get_SysTickInterval(rcc_Time_ms_t * const sysTickInterval)

🛠 CMake Integration​

  1. Include Rcc_Lib in your CMake library.
  2. Include Rcc_Port.h in your project.
  3. Link against the Rcc module implementation files.
  4. Configure the module as needed for your hardware.

License​

This project is licensed under the Creative Commons Attribution–NonCommercial 4.0 International (CC BY-NC 4.0).

You are free to use, modify, and share this work for non-commercial purposes, provided appropriate credit is given.

See LICENSE.md for full terms or visit creativecommons.org/licenses/by-nc/4.0.


Authors​

Contributions are welcome! Please open a pull request.