Functional Description
Clock and Prescaler
A programmable prescaler stage generates a 1Hz clock which is used to update the calendar. To minimize power consumption, the prescaler is split into 2 programmable prescalers.
A 9-bit asynchronous prescaler configured through the PREDIV_A bits of the RTC_PRER register.
A 9-bit synchronous prescaler configured through the PREDIV_S bits of the RTC_PRER register.
Note
It is recommended to configure the asynchronous prescaler to a high value to minimize consumption.
By default, the asynchronous prescaler division factor is set to 128, and the synchronous division factor is set to 256, to obtain an internal clock frequency of 1Hz (clk_spre) with 32.768kHz as RTCCLK.
fclk_apre is given by the following formula:
f_clk_apre = f_RTCCLK / (PREDIV_A + 1)
fclk_spre is given by the following formula:
f_clk_spre = f_clk_apre / (PREDIV_S + 1)
Programmable Alarm
The RTC unit provides one programmable alarm.
The programmable alarm function is enabled through the ALME bit in the RTC_CR register. The ALMF is set to ‘1’ if the calendar seconds, minutes, hours or days match the values programmed in the alarm registers RTC_ALMR1L and RTL_ALMR1H. Each calendar field can be independently selected through the MSKx bits. The alarm interrupt is enabled through the ALMIE bit in the RTC_CR register.
Alarm (if enabled by the OSEL [1:0] bits in RTC_CR) can be routed to the RTC_OUT output except when system is in deepsleep mode. The alarm output is a pulse which width is 1/RTCCLK.
Write Protection
After RTC domain reset, all the RTC registers are write-protected. Writing to the RTC registers is enabled by writing a key into the RTC_WPR register.
The following steps are required to unlock the write protection on all the RTC registers except for ALMF in RTC_ISR.
Write ‘0xCA’ into the RTC_WPR register.
Write ‘0x53’ into the RTC_WPR register.
Writing a wrong key reactivates the write protection. The protection mechanism is not affected by system reset.
Digital Calibration
The digital calibration can be used to compensate RTCCLK inaccuracy by adding (positive calibration) or masking (negative calibration) clock cycles at the output of the asynchronous prescaler (clk_apre).
Positive and negative calibrations are selected by setting the DCS bit to ‘0’ and ‘1’ in RTC_CALIBR register, respectively.
When positive calibration is enabled (DCS = ‘0’), DC clk_apre cycles are added every (CALP + 1) minutes, which causes the calendar to be updated sooner, thereby adjusting the effective RTC frequency to be a bit higher.
When negative calibration is enabled (DCS = ‘1’), DC clk_apre cycles are removed every (CALP + 1) minutes, which causes the calendar to be updated later, thereby adjusting the effective RTC frequency to be a bit lower.
DC and CALP can be configured through the RTC_CALIBR register. DC must be less than PREDIV_S in the RTC_PRER register.
The calibration parameter can be configured on-the-fly. Calibration resolution is determined by the frequency of clk_apre and the calibration period. The formula is as follows:
resolution = period_clk_apre / calp
CALP |
clk_apre (128Hz) |
clk_apre (256Hz) |
clk_apre (512Hz) |
|---|---|---|---|
1 min. |
130.2ppm |
65.1ppm |
32.55ppm |
2 min. |
65.1ppm |
32.55ppm |
16.27ppm |
4 min. |
32.55ppm |
16.27ppm |
8.14ppm |
8 min. |
16.27ppm |
8.14ppm |
4.07ppm |
Re-calibration on-the-fly:
The calibration register (RTC_CALIBR) can be updated on-the-fly while INITF = 0, by following these steps:
Poll the RECALPF (re-calibration pending flag).
If RECALPF is set to 0, write a new value to RTC_CALIBR if necessary; RECALPF is then automatically set to 1.
Within three clk_apre cycles after the write operation to RTC_CALIBR, the new calibration settings take effect.
Day Threshold Program
The RTC provides a day interrupt for users. When the day interrupt is needed, DAY_THRES [8:0] must be programmed first in RTC_CR, and then the DOVTHIE bit in RTC_CR must be set to enable the day over-threshold interrupt.
When DAY in REG_RTC_TR is greater than or equal to DAY_THRES in RTC_CR, DAY will be reset to 0.
Daylight Saving
The daylight saving time management is performed through the SUB1H, ADD1H, and BKP bits of the RTC_CR register.
Using SUB1H or ADD1H, the software can subtract or add one hour to the calendar in a single operation without going through the initialization procedure. In addition, the software can use the BKP bit to memorize this operation. It is recommended not to change the hour during the calendar hour increment as it could mask the incrementing of the calendar hour. (HW can handle this condition; if this condition occurs, HW will delay the SUB1H or ADD1H operation for 1 second.) When the calendar hour is 0 in the 24-hour system, SUB1H is not supported.
RTC Output
There are two types of RTC output pins which are in different power domains. One type is in the AON domain, which has power in active, sleep, and deep sleep modes. The other type is in the SYSON domain, which can output in active mode and sleep mode, but has no power and cannot output in deep sleep mode. If it had output before, the output continues after wakeup from deep sleep.
The output of rtc_out is determined by the OSEL [1:0] bits in RTC_CR.
Periodic Auto-wakeup
The wakeup function is enabled by setting the WUTE bit in the RTC_CR register.
The clock source of the wakeup timer is ck_spre (usually a 1Hz internal clock). When the ck_spre frequency is 1Hz, this allows a wakeup time from 1 second to around 36 hours with one-second resolution. 3 to 4 wakeup timer cycles after the initialization sequence is complete (refer to programming the wakeup timer), the timer starts counting down. The down-counting remains active in low-power modes. In addition, when it reaches 0, the WUTF flag is set in the RTC_ISR register, and the wakeup counter is automatically reloaded with its reload value (RTC_WUTR register value).
The WUTF flag must then be cleared by software.
When the periodic wakeup interrupt is enabled by setting the WUTIE bit in the RTC_CR register, it can exit the device from low-power modes.
System resets as well as low-power modes have no influence on the wakeup timer.
Once the wakeup timer is initialized and enabled, the wakeup auto-reload value can be changed according to the steps in programming the wakeup timer.
Each time the wakeup timer is enabled, 3 to 4 wakeup timer cycles (usually 3 to 4 seconds) are needed before the wakeup timer works and counting actually begins. Because the enable command is generated in the APB domain, it costs 2 RTC clocks to sync to the RTC domain; another 2 wakeup timer cycles are needed to sync to the wakeup timer domain, and one more wakeup cycle is needed before counting starts. After the sync process of the WUTE bit is complete, the WUTRSF flag bit is set for users to check.
Backup Register
The backup register contains four 32-bit registers, which are used for Realtek and users to save some data before reset happens.
The following table illustrates two reset types which can reset RTC module and backup register, which are both in AON domain. Other reset types can’t reset RTC and backup register.
Reset signal |
Reset type |
Description |
|---|---|---|
por_rstb |
POR |
A power on reset is generated when power on |
pdr_rstb |
PDR |
A power down reset is generated when a low level on the CHIP_EN pin (external reset) occurs |
The power domain of RTC and backup register is illustrated below.
Item |
Sleep (WoWLAN) |
Deepsleep |
|---|---|---|
RTC |
√ |
√ |
Backup register |
√ |
√ |
Note
√ means this module has power.