HAL RCC Use Cases

User application sets the system at maximum frequency

@startuml
participant Application
participant HAL
participant HAL_RCC
participant HAL_GPIO
participant HAL_FLASH
participant RCC_REG
note over Application : Enable HSIS oscillator
Application -> HAL_RCC : HAL_RCC_HSIS_Enable()
    HAL_RCC --> RCC_REG : enable HSIS oscillator
    HAL_RCC <-- RCC_REG
alt timeout case (HSIS Ready flag not set)
    HAL_RCC --> Application : HAL_ERROR
else
    HAL_RCC --> Application : HAL_OK
    note over Application: Increasing the number\nof wait states\nbecause of higher\nCPU frequency
    Application -> HAL_FLASH : HAL_FLASH_ITF_SetLatency\n(HAL_FLASH_ITF_LATENCY_4)
    note over Application : Set HSIS as source\nclock of system clock
    loop HSIS is selected as System Clock Source
    end
    Application -> HAL_RCC : HAL_RCC_SetSYSCLKSource\n(HAL_RCC_SYSCLK_SRC_HSIS)
    HAL_RCC --> RCC_REG : set system clock source
    note over HAL_RCC : update SystemCoreClock
    HAL_RCC -> HAL : HAL_InitTick
    HAL_RCC <-- HAL
    Application <-- HAL_RCC
end
@enduml

Called functions:

Reset the RCC clock configuration to the default system clock (HSIDIV3: 48 MHz)

@startuml
participant Application
participant HAL
participant HAL_RCC
participant LL_RCC
== HAL_RCC_ResetSystemClock function ==
Application -> HAL_RCC : HAL_RCC_ResetSystemClock
note over HAL_RCC : Enable HSIDIV3
HAL_RCC -> LL_RCC : LL_RCC_HSIDIV3_Enable
HAL_RCC <-- LL_RCC
HAL_RCC -> LL_RCC : LL_RCC_HSIDIV3_IsReady
alt timetout issue (HSIDIV3 not enabled)
    HAL_RCC --> Application : HAL_ERROR
else HSIDIV3 enabled
    note over HAL_RCC : Select HSIDIV3\nas system clock source
    HAL_RCC -> LL_RCC : LL_RCC_SetSysClkSource\n(LL_RCC_SYS_CLKSOURCE_HSIDIV3)
    HAL_RCC <-- LL_RCC
    HAL_RCC -> LL_RCC : LL_RCC_GetSysClkSource
    alt timetout issue (HSIDIV3 not selected as clock source)
        HAL_RCC --> Application : HAL_ERROR
    else HSIDIV3 selected as clock source
        HAL_RCC -> LL_RCC : LL_RCC_SetAHBPrescaler\n(LL_RCC_HCLK_PRESCALER_1)
        note over HAL_RCC : Set SystemCoreClock\nto HSI_RESET_VALUE
        HAL_RCC -> HAL: HAL_InitTick
        HAL --> HAL_RCC: HAL_OK
        HAL_RCC --> Application: HAL_OK
    end
end
@enduml

Called functions:

Enable HSE with unitary function example_1

@startuml
== Call HAL_RCC_HSE_Enable function (enable HSE) ==
Application -> HAL_RCC : HAL_RCC_HSE_Enable(HAL_RCC_HSE_ON)
    HAL_RCC -> LL_RCC : LL_RCC_HSE_Enable()
    LL_RCC -> HAL_RCC : LL_RCC_HSE_IsReady()
alt successful case (HSE Ready flag set)
    HAL_RCC --> Application : <font color=green> HAL_OK
else timeout case (HSE Ready flag not set)
    HAL_RCC --> Application : <font color=red> HAL_ERROR
end
@enduml

Called functions:

  • HAL_RCC_HSE_Enable()

Enable HSE with unitary function example_2

@startuml
== HSE transition ON -> BYPASS (need a transition to OFF) ==
Application -> HAL_RCC : HAL_RCC_HSE_Enable(HAL_RCC_HSE_ON)
HAL_RCC -> LL_RCC : LL_RCC_HSE_Enable()
LL_RCC -> HAL_RCC : LL_RCC_HSE_IsReady()
alt successful case (HSE Ready flag set)
    HAL_RCC --> Application : <font color=green> HAL_OK
    Application -> HAL_RCC : HAL_RCC_HSE_Disable()
    HAL_RCC -> LL_RCC : LL_RCC_HSE_Disable()
    LL_RCC -> HAL_RCC : LL_RCC_HSE_IsReady()
    alt successful case (HSE Ready flag reset)
        HAL_RCC --> Application : <font color=green> HAL_OK
        Application -> HAL_RCC : HAL_RCC_HSE_Enable(HAL_RCC_HSE_BYPASS)
        HAL_RCC -> LL_RCC : LL_RCC_HSE_EnableBypass()
        LL_RCC -> HAL_RCC : LL_RCC_HSE_IsReady()
        alt successful case (HSE Ready flag set)
            HAL_RCC --> Application : <font color=green> HAL_OK
        else timeout case (HSE Ready flag not set)
            HAL_RCC --> Application : <font color=red> HAL_ERROR
        end
    else timeout case (HSE Ready flag not reset)
        HAL_RCC --> Application : <font color=red> HAL_ERROR
    end
else timeout case (HSE Ready flag not set)
    HAL_RCC --> Application : <font color=red> HAL_ERROR
end
@enduml

Called functions:

  • HAL_RCC_HSE_Enable()

  • HAL_RCC_HSE_Disable()

Bus prescalers configuration

@startuml
== Call the global HAL_RCC_SetBusClockConfig ==
alt Increasing the number of wait states because of higher CPU frequency
Application -> HAL_FLASH : HAL_FLASH_ITF_GetLatency
HAL_FLASH --> Application : // return Current_latency
note over Application : if HAL_FLASH_ITF_LATENCY_X > Current_latency
Application -> HAL_FLASH : HAL_FLASH_ITF_SetLatency\n(HAL_FLASH_ITF_LATENCY_X)
Application <-- HAL_FLASH
end

note over Application : Fill hal_rcc_bus_clk_config_t structure\n(config_bus)
alt Increasing the BUS frequency divider
note over Application : if ({bus}_clk_divider > current_{bus}_clock)
Application -> HAL_RCC : HAL_RCC_SetBusClockConfig\n(&config_bus)
HAL_RCC -> RCC_REG : update {bus} dividers in RCC registers
HAL_RCC <-- RCC_REG
Application <-- HAL_RCC
end
loop HSIDIV3 is selected as System Clock Source
end
Application -> HAL_RCC : HAL_RCC_SetSYSCLKSource\n(HAL_RCC_SYSCLK_SRC_HSIS)
HAL_RCC -> RCC_REG : set system clock source
HAL_RCC <-- RCC_REG
Application <-- HAL_RCC
alt Decreasing the number of wait states because of lower CPU frequency
Application -> HAL_FLASH : HAL_FLASH_ITF_GetLatency
HAL_FLASH --> Application : // return Current_latency
note over Application : if HAL_FLASH_ITF_LATENCY_X < Current_latency
Application -> HAL_FLASH : HAL_FLASH_ITF_SetLatency\n(HAL_FLASH_ITF_LATENCY_X)
Application <-- HAL_FLASH
end
alt Decreasing the BUS frequency divider
note over Application : if ({bus}_clk_divider < current_{bus}_clock)
Application -> HAL_RCC : HAL_RCC_SetBusClockConfig\n(&config_bus)
HAL_RCC -> RCC_REG : update {bus} dividers in RCC registers
HAL_RCC <-- RCC_REG
Application <-- HAL_RCC
end
note over HAL_RCC : update SystemCoreClock
HAL_RCC -> HAL : HAL_InitTick
HAL --> HAL_RCC
Application <-- HAL_RCC
@enduml

Called functions:

Usage of HAL_RCC_SetConfigMCO

@startuml
participant Application
participant HAL_RCC
participant HAL_GPIO
participant LL_RCC
== GPIO initialization outside HAL_RCC_SetConfigMCO ==
note over Application : Initialize MCO pin on PA8\n  hal_gpio_init_t init_struct;\n  init_struct.Mode = HAL_GPIO_MODE_ALTERNATE;\n  init_struct.Speed = HAL_GPIO_SPEED_FREQ_HIGH;\n  init_struct.Pull = HAL_GPIO_PULL_NO;\n  init_struct.Alternate = HAL_GPIO_AF0_MCO;
Application -> HAL_RCC : HAL_RCC_GPIOA_EnableClock
HAL_RCC -> LL_RCC : LL_AHB2_GRP1_EnableClock\n(LL_AHB2_GRP1_PERIPH_GPIOA)
HAL_RCC <-- LL_RCC
Application <-- HAL_RCC
Application -> HAL_GPIO : HAL_GPIO_Init(HAL_GPIOA, &init_struct, HAL_GPIO_PIN_8)
Application <-- HAL_GPIO
Application -> HAL_RCC : HAL_RCC_SetConfigMCO
HAL_RCC -> LL_RCC : LL_RCC_ConfigMCO
HAL_RCC <-- LL_RCC
Application <-- HAL_RCC
@enduml

Called functions:

Usage of HAL_RCC_EnableLSCO

@startuml
participant Application
participant HAL_RCC
participant HAL_PWR
participant HAL_GPIO
participant LL_RCC
== GPIO initialization outside HAL_RCC_EnableLSCO ==
note over Application : Initialize LSCO pin on PA2\n  hal_gpio_init_t init_struct;\n  init_struct.mode = HAL_GPIO_MODE_ANALOG;\n  init_struct.speed = HAL_GPIO_SPEED_FREQ_HIGH;\n  init_struct.pull = HAL_GPIO_PULL_NO;
Application -> HAL_RCC : HAL_RCC_GPIOA_EnableClock
HAL_RCC --> Application
Application -> HAL_GPIO : HAL_GPIO_Init(HAL_GPIOA, &init_struct, HAL_GPIO_PIN_2)
HAL_GPIO --> Application
alt Write Protection domain is enabled
  Application -> HAL_PWR : HAL_PWR_DisableRTCDomainWriteProtection()
  HAL_PWR --> Application
end
Application -> HAL_RCC : HAL_RCC_EnableLSCO
HAL_RCC -> LL_RCC : LL_RCC_ConfigLSCO
HAL_RCC -> LL_RCC : LL_RCC_LSCO_Enable
HAL_RCC <-- LL_RCC
HAL_RCC --> Application : HAL_OK
@enduml

Called functions: