HAL RTC Use Cases

RTC initialization

@startuml

participant "User Application" as app
participant "System Drivers" as driv

== Initialization ==

app -> driv: HAL_init()
driv --> app

group Optional [If GPIO NVIC is needed in the application]
app -> driv: Configure GPIO, NVIC
driv --> app
end

app -> driv: HAL_RCC_RTC_EnableKernelClock()
driv --> app

app -> driv: HAL_RCC_RTC_SetKernelClkSource(clock_source)
driv --> app

group Enable clock source [choice 1]
app -> driv: HAL_RCC_LSE_Enable(mode, load, robustness)
driv --> app
end

group Enable clock source [choice 2]
app -> driv: HAL_RCC_LSI_Enable()
driv --> app
end

group Enable clock source [choice 3]
app -> driv: HAL_RCC_HSE_Enable(mode)
driv --> app
end

group Condition [If backup domain is available]
app -> driv: HAL_PWR_DisableRTCDomainWriteProtection()
driv --> app
end

@enduml

RTC calendar

@startuml

participant "User Application" as app
participant "Real Time Clock Driver" as rtc

== RTC initialization ==

app -> rtc : HAL_RTC_DisableWriteProtection()
rtc --> app : HAL_OK

app -> rtc : HAL_RTC_EnterInitMode()
rtc --> app : HAL_OK

group Optional [If using default parameters]
app -> rtc: HAL_RTC_SetConfig(&p_config)
rtc --> app: HAL_OK
end
== Calendar initialization in BCD or mixed mode ==

group Optional [If using default parameters]
app -> rtc : HAL_RTC_CALENDAR_SetConfig(&p_config_calendar)
rtc -> app : HAL_OK
end

group Set time and date [choice 1]
    app -> rtc : HAL_RTC_CALENDAR_SetTime(&p_time)
    rtc --> app : HAL_OK

    app -> rtc : HAL_RTC_CALENDAR_SetDate(&p_date)
    rtc --> app : HAL_OK
end

group Set time and date [choice 2]
    app -> rtc : HAL_RTC_CALENDAR_SetDateTime(&p_date, &p_time)
    rtc --> app : HAL_OK
end

== End Initialization ==

app -> rtc : HAL_RTC_ExitInitMode()
rtc --> app : HAL_OK

app -> rtc : HAL_RTC_EnableWriteProtection()
rtc --> app : HAL_OK

@enduml

Called functions:

RTC output

@startuml

participant "User Application" as app
participant "Real Time Clock Driver" as rtc

== Output tampalarm configuration ==

app -> rtc : HAL_RTC_OUTPUT_SetConfigTampalarm(&p_config)
rtc --> app : HAL_OK

== Output calibration configuration ==

app -> rtc : HAL_RTC_OUTPUT_SetConfigCalib(&p_config)
rtc --> app : HAL_OK

== Enable output ==

app -> rtc: HAL_RTC_OUTPUT_Enable(output)
rtc --> app : HAL_OK

== Disable output ==

app -> rtc : HAL_RTC_OUTPUT_Disable()
rtc --> app : HAL_OK

@enduml

Called functions:

RTC alarm

@startuml

participant "User Application" as app
participant "Real Time Clock Driver" as rtc
participant "Interruption" as int

== Alarm initialization ==
app -> rtc : HAL_RTC_ALARM_SetConfig(alarm, &p_config_alarm)
rtc --> app : HAL_OK
app -> rtc : HAL_RTC_ALARM_SetDateTime(alarm, &p_date_time)
rtc --> app : HAL_OK

== Alarm start ==

app -> rtc: HAL_RTC_ALARM_Start(alarm, interruption)

== Alarm timer IRQ handler ==
group Interruption mode
int -> rtc : HAL_RTC_ALARM_IRQHandler()
end
== Poll for alarm events ==

group Polling mode
app -> rtc: HAL_RTC_ALARM_PollForEvent(alarm, timeout_ms)
rtc --> app: HAL_OK
end

== Alarm stop ==

app -> rtc: HAL_RTC_ALARM_Stop(alarm)

@enduml

Called functions:

RTC timestamp

@startuml

participant "User Application" as app
participant "HAL Real Time Clock Driver" as rtc
participant "Interruption" as int

== Timestamp Configuration ==

app -> rtc : HAL_RTC_TIMESTAMP_SetConfig(&p_config_timestamp)
rtc --> app : HAL_OK

== Timestamp enable pin source ==

app -> rtc: HAL_RTC_TIMESTAMP_EnablePinSource()
rtc --> app : HAL_OK

== Timestamp interruption and IRQ handler ==

group Interruption Mode

app -> rtc: HAL_RTC_TIMESTAMP_EnableIT()
rtc --> app: HAL_OK

int -> rtc : HAL_RTC_TIMESTAMP_IRQHandler()
end

== Retrieve timestamp event ==

group Polling Mode

    app -> rtc: HAL_RTC_WAKEUP_PollForEvent(timeout_ms)
    rtc --> app: HAL_OK

    app -> rtc: HAL_RTC_TIMESTAMP_GetDateTime(&p_time, &p_date, &p_info)
    rtc --> app: HAL_OK

end

@enduml

Called functions:

Timestamp enable tamper source

@startuml

participant "User Application" as app
participant "HAL Real Time Clock Driver" as rtc
participant "Interruption" as int

== Timestamp Configuration ==

app -> rtc : HAL_RTC_TIMESTAMP_SetConfig(&p_config_timestamp)
rtc --> app : HAL_OK

== Timestamp enable pin source ==

app -> rtc: HAL_RTC_TIMESTAMP_EnablePinSource()
rtc --> app : HAL_OK

== Timestamp enable internal source ==

app -> rtc: HAL_RTC_TIMESTAMP_EnableInternalSource()
rtc --> app : HAL_OK

== Timestamp enable tamper source ==

app -> rtc: HAL_RTC_TIMESTAMP_EnableTamperSource()
rtc --> app : HAL_OK

== Timestamp interruption and IRQ handler ==

group Interruption Mode

app -> rtc: HAL_RTC_TIMESTAMP_EnableIT()
rtc --> app: HAL_OK

int -> rtc : HAL_RTC_TIMESTAMP_IRQHandler()
end

== Retrieve timestamp event ==

group Polling Mode

    app -> rtc: HAL_RTC_WAKEUP_PollForEvent(timeout_ms)
    rtc --> app: HAL_OK

    app -> rtc: HAL_RTC_TIMESTAMP_GetDateTime(&p_time, &p_date, &p_info)
    rtc --> app: HAL_OK

end

@enduml

Called functions:

RTC wake-up timer

@startuml

participant "User Application" as app
participant "Real Time Clock Driver" as rtc
participant "Interruption" as int

== RTC initialization ==

app -> rtc : HAL_RTC_DisableWriteProtection()
rtc --> app : HAL_OK

app -> rtc : HAL_RTC_EnterInitMode()
rtc --> app : HAL_OK

== Prescaler and Modes configuration ==

group Optional [Only when using the clock from the synchronous prescaler without default values]
app -> rtc : HAL_RTC_SetConfig(&p_config)
rtc --> app : HAL_OK
end

== Wake up timer initialization ==

group Optional [If using default parameters]
app -> rtc : HAL_RTC_WAKEUP_SetConfig(&p_config_wakeup_timer)
rtc --> app : HAL_OK
end

app -> rtc: HAL_RTC_WAKEUP_SetPeriod(&p_auto_reload_time, &p_auto_clear_time)
rtc --> app : HAL_OK

== End Initialization ==

app -> rtc : HAL_RTC_ExitInitMode()
rtc --> app : HAL_OK

app -> rtc : HAL_RTC_EnableWriteProtection()
rtc --> app : HAL_OK

== Start wakeup timer ==

app -> rtc : HAL_RTC_WAKEUP_Start(interruption)

== Wake up timer IRQ handler ==

group Interruption mode
int -> rtc : HAL_RTC_WAKEUP_IRQHandler(void)
end

== Wake up timer event ==
group Polling mode
    app -> rtc : HAL_RTC_WAKEUP_PollForEvent(timeout)
    rtc --> app: HAL_OK
end

== Stop wakeup timer ==

app -> rtc : HAL_RTC_WAKEUP_Stop(void)

@enduml

Called functions: