HAL RTC Overview

Introducing RTC

group RTC_Introduction

  • The real-time clock (RTC) peripheral provides accurate timekeeping and calendar functionality. It operates independently of the main microcontroller, ensuring continuous time tracking even during low-power modes or system resets. The RTC peripheral supports a wide range of features, including programmable alarms, periodic wake-up events, and timestamping capabilities.

Module and files

The following diagram illustrates the RTC module and its associated files.

Module and files diagram

Component diagram

The following diagram illustrates the software components involved in the RTC module. It shows the interactions between the user application, HAL drivers, low-level drivers, and the hardware components.


@startuml

!$use_RTC_core = 1
!$use_RTC_ll = 1
!$use_RTC_hal = 1

!$use_api_itf = 1
!$use_hal_itf = 1
!$use_ll_itf = 1
!$use_core_itf = 1

!$use_RTC_isr = 1

!$use_hal_service = 1
!$use_hal_rcc = 1
!$use_hal_rtc = 0

!$use_ll_rcc = 0

!$RTC = "RTC"
!$hal_api_itf = "HAL " + $RTC + " API"
!$appli_itf = "User Callback"
!$RTC_name = "HAL_"+$RTC
!$RTC_ISR = $RTC+" ISR"
!$ll_RTC = "LL_"+$RTC
!$HAL_RTC_itf = "HAL_RTC_StartDirectXfer()\nHAL_RTC_Abort_IT"
!$hal_rcc_itf = "\t\t\tHAL_RCC_"+$RTC+"_GetClockFreq()\n\t\t\tHAL_RCC_"+$RTC+"_EnableClock()"
!$hal_RTC_itf = "RTC CallBacks\nRTC Half transfer complete CallBack\nError CallBacks"
!$hal_generic_itf = "HAL_GetTick()"
!$ll_RTC_itf = "LL " + $RTC +" API"
!$RTC_xIRQ = $RTC+"x_IRQ"

<style>
componentDiagram {
arrow {
FontSize 8
}
interface {
FontSize 8
}
}
</style>

title $RTC Software Component Diagram

Package "Application Layer" #DarkMagenta {

component [Appli]
interface "$appli_itf" as APPLI_Interface
[Appli] -r- APPLI_Interface
}

package "HAL" #DarkOrange {
[$RTC_name]
!if ($use_hal_rtc == 1)
interface "$hal_RTC_itf" as HAL_RTC_Interface
[$RTC_name] -d- HAL_RTC_Interface
!endif
interface "$hal_api_itf" as HAL_RTC_APPLI_Interface
[$RTC_name] -u- HAL_RTC_APPLI_Interface

!if ($use_hal_service == 1)
  [HAL_SERVICE]
  interface "$hal_generic_itf" as HAL_Service_Interface
  [HAL_SERVICE] -r- HAL_Service_Interface
  [$RTC_name] -l-( HAL_Service_Interface
!endif

!if ($use_hal_rtc == 1)
  [HAL_RTC]
  interface "$HAL_RTC_itf" as HAL_RTC_Interface
  [HAL_RTC] -u- HAL_RTC_Interface
  [HAL_RTC] -u-( HAL_RTC_Interface
  [$RTC_name] --( HAL_RTC_Interface
!endif
!if ($use_hal_rcc == 1)
  [HAL_RCC]
  interface "$hal_rcc_itf" as HAL_RCC_Interface
  [HAL_RCC] -l- HAL_RCC_Interface
  [$RTC_name] -r-( HAL_RCC_Interface
!endif
}

[Appli] -d-( HAL_RTC_APPLI_Interface
[$RTC_name] -u-( APPLI_Interface

package "Low Layer" #Technology {

!if ($use_RTC_ll == 1)
  [$ll_RTC]
  interface "$ll_RTC_itf" as LL_RTC_Interface
  [$ll_RTC]  -u- LL_RTC_Interface
!endif

!if ($use_RTC_isr == 1)
interface "$RTC_ISR" as RTC_ISR
[$RTC_ISR] -U- RTC_ISR
[$RTC_ISR]
!endif

[CMSIS-Devices]
!if ($use_ll_rcc == 1)
  [LL_RCC]
  interface "LL RCC API" as LL_RCC_API
  [LL_RCC] -u- LL_RCC_API
  [HAL_RCC] -d-(LL_RCC_API
!endif

!if ($use_hal_rtc == 1)
  [RTC ISR]
  interface "RTC ISR" as RTC_ISR
  [RTC ISR] -u- RTC_ISR
!endif
}

package "HW" #LightCyan {
[STM32_HW]
!if ($use_RTC_isr == 1)
interface "$RTC_xIRQ" as RTCx_IRQ
[STM32_HW] -u- RTCx_IRQ
!endif
!if ($use_hal_rtc == 1)
interface "RTCx_IRQ_Ch" as RTC_IRQ_CH
[STM32_HW] -u- RTC_IRQ_CH
[RTC ISR] -d-( RTC_IRQ_CH
[HAL_RTC] --( RTC_ISR
!endif
}
!if ($use_RTC_ll == 1)
[$RTC_name] -d-( LL_RTC_Interface
[$ll_RTC] .r.> [CMSIS-Devices]: $RTC register def
[STM32_HW] <.u. [$ll_RTC] : $RTC registers R/W
!else
[$RTC_name] .d.> [CMSIS-Devices]: $RTC register def
[STM32_HW] <.l. [$RTC_name] : $RTC registers R/W
!endif
!if ($use_RTC_isr == 1)
[$RTC_ISR] -d-( RTCx_IRQ
[$RTC_name] -d-( RTC_ISR
!endif
!if ($use_ll_rcc == 1)
[STM32_HW] <.u. [LL_RCC] : RCC registers R/W
!endif

@enduml

Configuration table

The following table lists the configuration defines for the HAL RTC module, specifying their locations, default values, and descriptions:

group RTC_Configuration_Table

Configuration inside the RTC driver

This configuration table is under development.

Configuration defines

Description

Default value

Note

PRODUCT

from IDE

NA

The selected device (e.g. STM32ynxx)

USE_HAL_RTC_MODULE

from hal_conf.h

1

Allows use of the HAL RTC module

USE_ASSERT_DBG_PARAM

from IDE

None

Allows use of the assert check parameters

USE_HAL_CHECK_PARAM

from hal_conf.h

0

Allows use of the run-time check parameters