HAL RCC use cases

rcc_uc_u5_set_system_max_frequency

@startuml

participant Application

participant HAL

participant HAL_RCC

participant HAL_GPIO

participant HAL_PWR

participant HAL_FLASH

participant RCC_REG

note over Application : Configure the main internal\nregulator output voltage

Application -> HAL_RCC :HAL_RCC_PWR_EnableClock

Application -> HAL_PWR :HAL_PWR_ControlVoltageScaling\n(PWR_REGULATOR_VOLTAGE_SCALE1)

note over HAL_PWR : EPOD enabled

note over Application : Enable HSI oscillator

Application -> HAL_RCC : HAL_RCC_HSI_Enable()

    HAL_RCC --> RCC_REG : enable HSI oscillator

    HAL_RCC <-- RCC_REG

alt timeout case (HSI Ready flag not set)

    HAL_RCC --> Application : HAL_ERROR

else

    HAL_RCC --> Application : HAL_OK

    note over Application : Configure PLL1

    Application -> HAL_RCC : HAL_RCC_PLL1_SetConfig

    HAL_RCC --> Application : HAL_OK

    Application -> HAL_RCC : HAL_RCC_PLL1_Enable

    alt error case (PLL1 ready flag not set)

        HAL_RCC --> Application : HAL_ERROR

    else PLL1 ready flag set

        HAL_RCC --> Application : HAL_OK

        Application -> HAL_RCC : HAL_RCC_PLL1_EnableOutput\n(HAL_RCC_PLL1_SYSCLK)

        note over Application: Increasing the number\nof wait states\nbecause of higher\nCPU frequency

        Application -> HAL_FLASH : HAL_FLASH_SetLatency\n(FLASH_LATENCY_4)

        note over Application : Set PLL as source\nclock of system clock

        loop PLL is selected as System Clock Source and EPOD enabled

        Application -> HAL_PWR : READ PWR_VOSR_BOOSTRDY == 0

        end

        Application -> HAL_RCC : HAL_RCC_SetSYSCLKSource\n(HAL_RCC_SYSCLK_SRC_PLLCLK)

        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

end

@enduml

Called functions:

rcc_uc_u5_reset_system_clock

@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 MSIS

HAL_RCC -> LL_RCC : LL_RCC_MSIS_Enable

HAL_RCC <-- LL_RCC

HAL_RCC -> LL_RCC : LL_RCC_MSIS_IsReady

alt timetout issue (MSIS not enabled)

    HAL_RCC --> Application : HAL_ERROR

else MSIS enabled

    note over HAL_RCC : Set MSIRANGE default value

    HAL_RCC -> LL_RCC : LL_RCC_MSI_EnableRangeSelection()

    HAL_RCC -> LL_RCC : LL_RCC_MSIS_SetRange\n(HAL_RCC_MSIS_FREQ_4MHZ)

    note over HAL_RCC : Select MSIS\nas system clock source

    HAL_RCC -> LL_RCC : LL_RCC_SetSysClkSource\n(LL_RCC_SYS_CLKSOURCE_MSIS)

    HAL_RCC <-- LL_RCC

    HAL_RCC -> LL_RCC : LL_RCC_GetSysClkSource

    alt timetout issue (MSIS not selected as clock source)

        HAL_RCC --> Application : HAL_ERROR

    else MSIS selected as clock source

        note over HAL_RCC : Set SystemCoreClock\nto MSI_RESET_VALUE

        HAL_RCC -> HAL: HAL_InitTick

        HAL --> HAL_RCC: HAL_OK

        HAL_RCC --> Application: HAL_OK

    end

end

@enduml

Called functions:

rcc_uc_u5_enable_hse_unitary_function

@startuml

== Call HAL_RCC_HSE_Enable function (enable HSE) ==

Application -> HAL_RCC : HAL_RCC_HSE_Enable(HAL_RCC_HSE_CONFIG_ON)

    HAL_RCC -> RCC_REG : enable HSE oscillator

alt successful case (HSE Ready flag set)

    HAL_RCC --> Application : HAL_OK

else timeout case (HSE Ready flag not set)

    HAL_RCC --> Application : HAL_ERROR

end

@enduml

Called functions:

  • HAL_RCC_HSE_Enable()

rcc_uc_u5_hse_transition_on_to_bypass

@startuml

== HSE transition ON -> BYPASS (need a transition to OFF) ==

Application -> HAL_RCC : HAL_RCC_HSE_Enable(HAL_RCC_HSE_CONFIG_ON)

HAL_RCC -> RCC_REG : enable HSE oscillator

alt successful case (HSE Ready flag set)

    HAL_RCC --> Application : HAL_OK

    Application -> HAL_RCC : HAL_RCC_HSE_Disable()

    HAL_RCC -> RCC_REG : disable HSE oscillator

    alt successful case (HSE Ready flag reset)

        HAL_RCC --> Application : HAL_OK

        Application -> HAL_RCC : HAL_RCC_HSE_Enable(HAL_RCC_HSE_BYPASS)

        HAL_RCC -> RCC_REG : Enable bypass mode

        alt successful case (HSE Ready flag set)

            HAL_RCC --> Application : HAL_OK

        else timeout case (HSE Ready flag not set)

            HAL_RCC --> Application : HAL_ERROR

        end

    else timeout case (HSE Ready flag not reset)

        HAL_RCC --> Application : HAL_ERROR

    end

else timeout case (HSE Ready flag not set)

    HAL_RCC --> Application : HAL_ERROR

end

@enduml

Called functions:

  • HAL_RCC_HSE_Enable()

  • HAL_RCC_HSE_Disable()

rcc_uc_u5_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_GetLatency

HAL_FLASH --> Application : // return Current_latency

note over Application : if HAL_FLASH_LATENCY_X > Current_latency

Application -> HAL_FLASH : HAL_FLASH_SetLatency\n(HAL_FLASH_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 PLL is selected as System Clock Source and EPOD enabled

Application -> HAL_PWR : READ PWR_VOSR_BOOSTRDY == 0

Application <-- HAL_PWR

end

Application -> HAL_RCC : HAL_RCC_SetSYSCLKSource\n(HAL_RCC_SYSCLK_SRC_PLLCLK)

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_GetLatency

HAL_FLASH --> Application : // return Current_latency

note over Application : if HAL_FLASH_LATENCY_X < Current_latency

Application -> HAL_FLASH : HAL_FLASH_SetLatency\n(HAL_FLASH_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:

rcc_uc_u5_configure_pll1

@startuml

participant Application

participant HAL_RCC

participant LL_RCC

note over Application : Fill hal_rcc_pll_config_t structure\n(config_pll)

Application -> HAL_RCC : HAL_RCC_PLL1_SetConfig(&my_config)

alt error case (PLL1 already configured)

    HAL_RCC --> Application : HAL_ERROR

else PLL1 correctly configured

    HAL_RCC --> LL_RCC : LL_RCC_PLL1_Config

    HAL_RCC --> LL_RCC : LL_RCC_PLL1FRACN_Disable();

    HAL_RCC --> LL_RCC : LL_RCC_PLL1_SetFRACN

    HAL_RCC --> LL_RCC : LL_RCC_PLL1FRACN_Enable();

    HAL_RCC --> LL_RCC : LL_RCC_PLL1_SetVCOInputRange

    HAL_RCC --> Application : HAL_OK

    Application -> HAL_RCC : HAL_RCC_PLL1_Enable

    alt error case (PLL1 ready flag not set)

        HAL_RCC --> Application : HAL_ERROR

    else PLL1 ready flag set

        HAL_RCC --> Application : HAL_OK

        Application -> HAL_RCC : HAL_RCC_PLL1_EnableOutput\n(HAL_RCC_PLL1_SYSCLK)

    end

end

@enduml

Called functions:

rcc_uc_u5_configure_secure_and_privilege_attributes

@startuml

Application -> HAL_RCC : HAL_RCC_SetSecurity\n(HAL_RCC_HSI, HAL_RCC_SEC)

HAL_RCC -> RCC_REG : Enable security for HSI

Application -> HAL_RCC : HAL_RCC_EnablePriv

HAL_RCC -> RCC_REG : Enable privilege

Application -> HAL_RCC : HAL_RCC_SetSecurity\n(HAL_RCC_HSE, HAL_RCC_NSEC)

HAL_RCC -> RCC_REG : Disable security for HSE

@enduml

Called functions:

  • HAL_RCC_SetSecurity()

  • HAL_RCC_EnablePriv()

rcc_uc_u5_periph_clk_config_pll2_sai1

@startuml

== Call HAL_RCC_PeriphCLKConfig function (PLL2 clk src for SAI1) ==

Application -> HAL_RCC : HAL_RCC_PeriphCLKConfig\n(SAI1,clk_src:PLL2)

HAL_RCC -> LL_RCC : LL_RCC_PLL2_Disable

alt successful case (PLL is disabled)

    HAL_RCC --> LL_RCC : LL_RCC_PLL2_Config

    HAL_RCC --> LL_RCC : LL_RCC_PLL2_EnableOutput\n(LL_RCC_PLL2_OUTPUT_R)

    HAL_RCC --> LL_RCC : LL_RCC_PLL2_Enable

    alt successful case (PLL is enabled)

        HAL_RCC --> LL_RCC : LL_RCC_SetSAIClockSource\n(PLL2)

        HAL_RCC --> Application : HAL_OK

    else timeout case (PLL is not enabled)

        HAL_RCC --> Application : HAL_ERROR

    end

else timeout case (PLL is not disabled)

    HAL_RCC --> Application : HAL_ERROR

end

@enduml

Called functions:

  • HAL_RCC_PeriphCLKConfig()

  • LL_RCC_PLL2_Disable()

  • LL_RCC_PLL2_Config()

  • LL_RCC_PLL2_EnableOutput()

  • LL_RCC_PLL2_Enable()

rcc_uc_u5_periph_clk_config_rtc_lsi

@startuml

participant Application

participant HAL_RCC

participant LL_RCC_REG

participant LL_PWR_REG

== Call HAL_RCC_LSI_Enable function (enable LSI) ==

Application -> HAL_RCC : HAL_RCC_LSI_Enable(HAL_RCC_LSI_DIV1)

    HAL_RCC -> LL_RCC_REG : enable LSI oscillator

    HAL_RCC <-- LL_RCC_REG

    HAL_RCC --> Application : HAL_OK

== Enable access to backup domain ==

Application -> HAL_RCC : HAL_RCC_PWR_EnableClock()

    HAL_RCC -> LL_RCC_REG : enable PWR clock

    HAL_RCC <-- LL_RCC_REG

    HAL_RCC --> Application

Application -> LL_PWR_REG : HAL_PWR_DisableRTCDomainWriteProtection()

    LL_PWR_REG --> Application

loop max 2 ms

Application -> LL_PWR_REG : HAL_PWR_IsEnabledRTCDomainWriteProtection() != HAL_PWR_RTC_DOMAIN_WRP_DISABLED

    LL_PWR_REG --> Application

end

note left: access should be enabled\nbefore timeout

== Call HAL_RCC_PeriphCLKConfig function (LSI clk src for RTC) ==

Application -> HAL_RCC : HAL_RCC_PeriphCLKConfig\n(RTC,clk_src:LSI)

    HAL_RCC --> LL_RCC_REG : LL_RCC_SetRTCClockSource\n(LSI)

    HAL_RCC <-- LL_RCC_REG

    HAL_RCC --> Application : HAL_OK

@enduml

Called functions:

rcc_uc_u5_set_kernel_clk_source_sai1

@startuml

== Call HAL_RCC_SAI1_SetKernelClkSource function (PLL2) ==

note over Application : Fill hal_rcc_pll2_config_t structure\n(config_pll)

Application -> HAL_RCC : HAL_RCC_PLL2_SetConfig(&my_config)

alt error case (PLL2 already configured)

    HAL_RCC --> Application : HAL_ERROR

else PLL2 correctly configured

    HAL_RCC --> Application : HAL_OK

    Application -> HAL_RCC : HAL_RCC_PLL2_Enable

    alt error case (PLL2 ready flag not set)

        HAL_RCC --> Application : HAL_ERROR

    else PLL2 ready flag set

        HAL_RCC --> Application : HAL_OK

        Application -> HAL_RCC : HAL_RCC_PLL2_EnableOutput\n(HAL_RCC_PLL2_OUTPUT_R)

        HAL_RCC --> LL_RCC : LL_RCC_PLL2_EnableOutput\n(LL_RCC_PLL2_OUTPUT_R)

        HAL_RCC --> Application: HAL_OK

        Application -> HAL_RCC : HAL_RCC_SAI1_SetKernelClkSource\n(clk_src:PLL2)

        HAL_RCC --> LL_RCC : LL_RCC_SetSAIClockSource\n(PLL2)

        HAL_RCC --> Application

    end

end

@enduml

Called functions:

rcc_uc_u5_configure_and_enable_pll2

@startuml

note over Application : Disable PLL2

Application -> HAL_RCC : HAL_RCC_PLL2_Disable()

HAL_RCC -> LL_RCC : LL_RCC_PLL2_Disable

HAL_RCC <-- LL_RCC

alt timetout issue (PLL2 ready flag not reset)

    HAL_RCC --> Application : HAL_ERROR

else PLL2 correctly disabled

  HAL_RCC --> Application : HAL_OK

  note over Application : Enable PLL2 source is not enabled\n

  Application -> HAL_RCC : HAL_RCC_HSI_Enable()

  HAL_RCC -> LL_RCC : LL_RCC_HSI_Enable

  HAL_RCC <-- LL_RCC

  alt timetout issue (HSI ready flag not set)

    HAL_RCC --> Application : HAL_ERROR

  else HSI Ready

    HAL_RCC --> Application : HAL_OK

    note over Application : Configure PLL2\n(fill hal_rcc_pll_config_t structure)

    Application -> HAL_RCC : HAL_RCC_PLL2_SetConfig()

    HAL_RCC -> LL_RCC : LL_RCC_PLL2_Config

    HAL_RCC <-- LL_RCC

    HAL_RCC -> LL_RCC : LL_RCC_PLL2FRACN_Disable

    HAL_RCC <-- LL_RCC

    HAL_RCC -> LL_RCC : LL_RCC_PLL2_SetFRACN

    HAL_RCC <-- LL_RCC

    HAL_RCC -> LL_RCC : LL_RCC_PLL2FRACN_Enable

    HAL_RCC <-- LL_RCC

    HAL_RCC -> LL_RCC : LL_RCC_PLL2_SetVCOInputRange

    HAL_RCC <-- LL_RCC

    HAL_RCC --> Application : HAL_OK

    note over Application : Select output(s) to activate

    Application -> HAL_RCC : HAL_RCC_PLL2_EnableOutput()

    HAL_RCC -> LL_RCC : LL_RCC_PLL2_EnableOutput

    HAL_RCC <-- LL_RCC

    HAL_RCC --> Application : HAL_OK

    note over Application : Enable PLL2

    Application -> HAL_RCC : HAL_RCC_PLL2_Enable()

    HAL_RCC -> LL_RCC : LL_RCC_PLL2_Enable

    HAL_RCC <-- LL_RCC

    alt timetout issue (PLL2 ready flag not set)

        HAL_RCC --> Application : HAL_ERROR

    else PLL2 correctly disabled

        HAL_RCC --> Application : HAL_OK

    end

end

end

@enduml

Called functions:

rcc_uc_u5_set_config_mco

@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_AF_PP;\n  init_struct.Speed = HAL_GPIO_SPEED_FREQ_HIGH;\n  init_struct.Pull = HAL_GPIO_NOPULL;\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:

rcc_uc_u5_enable_lsco

@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_NOPULL;

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 PWR is disabled

  Application -> HAL_PWR : HAL_RCC_PWR_EnableClock

  HAL_PWR --> Application

end

alt Backup domain is disabled

  Application -> HAL_PWR : HAL_PWR_EnableBkUpAccess

  HAL_PWR --> Application

end

Application -> HAL_RCC : HAL_RCC_EnableLSCO

HAL_RCC -> LL_RCC : LL_RCC_ConfigLSCO

HAL_RCC <-- LL_RCC

HAL_RCC --> Application : HAL_OK

@enduml

Called functions: