libopencm3
A free/libre/open-source firmware library for various ARM Cortex-M3 microcontrollers.

Defined Constants and Types for the STM32L1xx RTC More...

Collaboration diagram for RTC Defines:

Modules

 RTC Registers
 Real Time Clock registers.
 
 RTC Time register (RTC_TR) values
 Note: Bits [31:23], 15, and 7 are reserved, and must be kept at reset value.
 
 RTC Date register (RTC_DR) values
 Note: Bits [31:24] and [7:6] are reserved, and must be kept at reset value.
 
 RTC control register (RTC_CR) values
 Note: Bits [31:24] are reserved, and must be kept at reset value.
 
 RTC initialization and status register (RTC_ISR) values
 Note: Bits [31:17] and [15] are reserved, and must be kept at reset value.
 
 RTC prescaler register (RTC_PRER) values
 
 RTC Alarm register values
 Applies to RTC_ALRMAR and RTC_ALRMBR.
 
 RTC time stamp time register (RTC_TSTR) values
 
 RTC time stamp date register (RTC_TSDR) values
 
 RTC calibration register (RTC_CALR) values
 
 RTC tamper and alternate function configuration register (RTC_TAFCR) values
 

Macros

#define RTC_CALIBR_DCS   (1 << 7)
 
#define RTC_CALIBR_DC_SHIFT   (0)
 
#define RTC_CALIBR_DC_MASK   (0x1f)
 
#define RTC_SHIFTR_ADD1S   (1<<31)
 
#define RTC_SHIFTR_SUBFS_SHIFT   (0)
 
#define RTC_SHIFTR_SUBFS_MASK   (0x7fff)
 
#define RTC_ALRMXSSR_MASKSS_SHIFT   (24)
 
#define RTC_ALARXSSR_MASKSS_MASK   (0xf)
 
#define RTC_ALRMXSSR_SS_SHIFT   (0)
 
#define RTC_ALARXSSR_SS_MASK   (0x7fff)
 

Enumerations

enum  rtc_weekday {
  RTC_DR_WDU_MON = 0x01 , RTC_DR_WDU_TUE , RTC_DR_WDU_WED , RTC_DR_WDU_THU ,
  RTC_DR_WDU_FRI , RTC_DR_WDU_SAT , RTC_DR_WDU_SUN
}
 

Functions

void rtc_set_prescaler (uint32_t sync, uint32_t async)
 Set RTC prescalars. More...
 
void rtc_wait_for_synchro (void)
 Wait for RTC registers to be synchronised with the APB1 bus. More...
 
void rtc_lock (void)
 Lock write access to the RTC registers. More...
 
void rtc_unlock (void)
 Unlock write access to the RTC registers. More...
 
void rtc_set_wakeup_time (uint16_t wkup_time, uint8_t rtc_cr_wucksel)
 Sets the wakeup time auto-reload value. More...
 
void rtc_clear_wakeup_flag (void)
 Clears the wakeup flag. More...
 
void rtc_set_init_flag (void)
 Sets the initialization flag. More...
 
void rtc_clear_init_flag (void)
 Clears (resets) the initialization flag. More...
 
bool rtc_init_flag_is_ready (void)
 Returns if the RTC_ISR init flag RTC_ISR_INITF is set. More...
 
void rtc_wait_for_init_ready (void)
 Waits infinitely for initialization flag to be set in RTC_ISR. More...
 
void rtc_set_bypass_shadow_register (void)
 
void rtc_enable_bypass_shadow_register (void)
 Sets the bypass shadow bit in RTC_CR. More...
 
void rtc_disable_bypass_shadow_register (void)
 Clears the bypass shadow bit in RTC_CR. More...
 
void rtc_set_am_format (void)
 Sets the RTC control register hour format to AM (24h) More...
 
void rtc_set_pm_format (void)
 Sets the RTC control register hour format to PM (12h) More...
 
void rtc_calendar_set_year (uint8_t year)
 Sets the RTC BCD calendar year value. More...
 
void rtc_calendar_set_weekday (enum rtc_weekday rtc_dr_wdu)
 Sets the RTC BCD calendar weekday. More...
 
void rtc_calendar_set_month (uint8_t month)
 Sets the RTC BCD calendar month value. More...
 
void rtc_calendar_set_day (uint8_t day)
 Sets the RTC BCD calendar day value. More...
 
void rtc_calendar_set_date (uint8_t year, uint8_t month, uint8_t day, enum rtc_weekday rtc_dr_wdu)
 Sets the RTC BCD calendar value. More...
 
void rtc_time_set_hour (uint8_t hour, bool use_am_notation)
 Sets the RTC BCD time hour value. More...
 
void rtc_time_set_minute (uint8_t minute)
 Sets the RTC BCD time minute value. More...
 
void rtc_time_set_second (uint8_t second)
 Sets the RTC BCD time second value. More...
 
void rtc_time_set_time (uint8_t hour, uint8_t minute, uint8_t second, bool use_am_notation)
 Sets the RTC BCD time. More...
 

Detailed Description

Defined Constants and Types for the STM32L1xx RTC

This covers the "version 2" RTC peripheral.

Version
1.0.0
Date
5 December 2012

LGPL License Terms libopencm3 License

Author
© 2012 Karl Palsson karlp.nosp@m.@twe.nosp@m.ak.ne.nosp@m.t.au

This is completely different to the v1 RTC periph on the F1 series devices. It has BCD counters, with automatic leapyear corrections and daylight savings support. This peripheral is used on the F0, F2, F3, F4 and L1 devices, though some only support a subset.

Macro Definition Documentation

◆ RTC_ALARXSSR_MASKSS_MASK

#define RTC_ALARXSSR_MASKSS_MASK   (0xf)

Definition at line 424 of file rtc_common_l1f024.h.

◆ RTC_ALARXSSR_SS_MASK

#define RTC_ALARXSSR_SS_MASK   (0x7fff)

Definition at line 427 of file rtc_common_l1f024.h.

◆ RTC_ALRMXSSR_MASKSS_SHIFT

#define RTC_ALRMXSSR_MASKSS_SHIFT   (24)

Definition at line 423 of file rtc_common_l1f024.h.

◆ RTC_ALRMXSSR_SS_SHIFT

#define RTC_ALRMXSSR_SS_SHIFT   (0)

Definition at line 426 of file rtc_common_l1f024.h.

◆ RTC_CALIBR_DC_MASK

#define RTC_CALIBR_DC_MASK   (0x1f)

Definition at line 302 of file rtc_common_l1f024.h.

◆ RTC_CALIBR_DC_SHIFT

#define RTC_CALIBR_DC_SHIFT   (0)

Definition at line 301 of file rtc_common_l1f024.h.

◆ RTC_CALIBR_DCS

#define RTC_CALIBR_DCS   (1 << 7)

Definition at line 299 of file rtc_common_l1f024.h.

◆ RTC_SHIFTR_ADD1S

#define RTC_SHIFTR_ADD1S   (1<<31)

Definition at line 333 of file rtc_common_l1f024.h.

◆ RTC_SHIFTR_SUBFS_MASK

#define RTC_SHIFTR_SUBFS_MASK   (0x7fff)

Definition at line 336 of file rtc_common_l1f024.h.

◆ RTC_SHIFTR_SUBFS_SHIFT

#define RTC_SHIFTR_SUBFS_SHIFT   (0)

Definition at line 335 of file rtc_common_l1f024.h.

Enumeration Type Documentation

◆ rtc_weekday

Enumerator
RTC_DR_WDU_MON 
RTC_DR_WDU_TUE 
RTC_DR_WDU_WED 
RTC_DR_WDU_THU 
RTC_DR_WDU_FRI 
RTC_DR_WDU_SAT 
RTC_DR_WDU_SUN 

Definition at line 429 of file rtc_common_l1f024.h.

Function Documentation

◆ rtc_calendar_set_date()

void rtc_calendar_set_date ( uint8_t  year,
uint8_t  month,
uint8_t  day,
enum rtc_weekday  rtc_dr_wdu 
)

Sets the RTC BCD calendar value.

Requires unlocking the RTC write-protection (RTC_WPR)

The year value should only be the abbreviated year tens, meaning if 2021 is desired pass in only 21.

Definition at line 271 of file rtc_common_l1f024.c.

References rtc_calendar_set_day(), rtc_calendar_set_month(), rtc_calendar_set_weekday(), and rtc_calendar_set_year().

Here is the call graph for this function:

◆ rtc_calendar_set_day()

void rtc_calendar_set_day ( uint8_t  day)

Sets the RTC BCD calendar day value.

Requires unlocking the RTC write-protection (RTC_WPR)

Definition at line 255 of file rtc_common_l1f024.c.

References _rtc_dec_to_bcd(), RTC_DR, RTC_DR_DT_MASK, RTC_DR_DT_SHIFT, RTC_DR_DU_MASK, and RTC_DR_DU_SHIFT.

Referenced by rtc_calendar_set_date().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ rtc_calendar_set_month()

void rtc_calendar_set_month ( uint8_t  month)

Sets the RTC BCD calendar month value.

Requires unlocking the RTC write-protection (RTC_WPR)

Definition at line 242 of file rtc_common_l1f024.c.

References _rtc_dec_to_bcd(), RTC_DR, RTC_DR_MT_MASK, RTC_DR_MT_SHIFT, RTC_DR_MU_MASK, and RTC_DR_MU_SHIFT.

Referenced by rtc_calendar_set_date().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ rtc_calendar_set_weekday()

void rtc_calendar_set_weekday ( enum rtc_weekday  rtc_dr_wdu)

Sets the RTC BCD calendar weekday.

Requires unlocking the RTC write-protection (RTC_WPR)

Definition at line 231 of file rtc_common_l1f024.c.

References RTC_DR, RTC_DR_WDU_MASK, and RTC_DR_WDU_SHIFT.

Referenced by rtc_calendar_set_date().

Here is the caller graph for this function:

◆ rtc_calendar_set_year()

void rtc_calendar_set_year ( uint8_t  year)

Sets the RTC BCD calendar year value.

Requires unlocking the RTC write-protection (RTC_WPR)

The year value should only be the abbreviated year tens, meaning if 2021 is desired pass in only 21.

Definition at line 218 of file rtc_common_l1f024.c.

References _rtc_dec_to_bcd(), RTC_DR, RTC_DR_YT_MASK, RTC_DR_YT_SHIFT, RTC_DR_YU_MASK, and RTC_DR_YU_SHIFT.

Referenced by rtc_calendar_set_date().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ rtc_clear_init_flag()

void rtc_clear_init_flag ( void  )

Clears (resets) the initialization flag.

Requires unlocking backup domain write protection (PWR_CR_DBP)

Definition at line 145 of file rtc_common_l1f024.c.

References RTC_ISR.

◆ rtc_clear_wakeup_flag()

void rtc_clear_wakeup_flag ( void  )

Clears the wakeup flag.

This function should be called first in the rtc_wkup_isr()

Definition at line 125 of file rtc_common_l1f024.c.

References RTC_ISR.

◆ rtc_disable_bypass_shadow_register()

void rtc_disable_bypass_shadow_register ( void  )

Clears the bypass shadow bit in RTC_CR.

Requires unlocking backup domain write protection (PWR_CR_DBP)

Definition at line 185 of file rtc_common_l1f024.c.

References RTC_CR.

◆ rtc_enable_bypass_shadow_register()

void rtc_enable_bypass_shadow_register ( void  )

Sets the bypass shadow bit in RTC_CR.

Requires unlocking backup domain write protection (PWR_CR_DBP)

Definition at line 175 of file rtc_common_l1f024.c.

References RTC_CR, and RTC_CR_BYPSHAD.

◆ rtc_init_flag_is_ready()

bool rtc_init_flag_is_ready ( void  )

Returns if the RTC_ISR init flag RTC_ISR_INITF is set.

Requires unlocking backup domain write protection (PWR_CR_DBP)

Definition at line 155 of file rtc_common_l1f024.c.

References RTC_ISR, and RTC_ISR_INITF.

Referenced by rtc_wait_for_init_ready().

Here is the caller graph for this function:

◆ rtc_lock()

void rtc_lock ( void  )

Lock write access to the RTC registers.

Definition at line 86 of file rtc_common_l1f024.c.

References RTC_WPR.

◆ rtc_set_am_format()

void rtc_set_am_format ( void  )

Sets the RTC control register hour format to AM (24h)

Requires unlocking backup domain write protection (PWR_CR_DBP)

Definition at line 195 of file rtc_common_l1f024.c.

References RTC_CR.

◆ rtc_set_bypass_shadow_register()

void rtc_set_bypass_shadow_register ( void  )

◆ rtc_set_init_flag()

void rtc_set_init_flag ( void  )

Sets the initialization flag.

Requires unlocking backup domain write protection (PWR_CR_DBP)

Definition at line 135 of file rtc_common_l1f024.c.

References RTC_ISR, and RTC_ISR_INIT.

◆ rtc_set_pm_format()

void rtc_set_pm_format ( void  )

Sets the RTC control register hour format to PM (12h)

Requires unlocking backup domain write protection (PWR_CR_DBP)

Definition at line 205 of file rtc_common_l1f024.c.

References RTC_CR, and RTC_CR_FMT.

◆ rtc_set_prescaler()

void rtc_set_prescaler ( uint32_t  sync,
uint32_t  async 
)

Set RTC prescalars.

This sets the RTC synchronous and asynchronous prescalars.

Definition at line 42 of file rtc_common_l1f024.c.

References RTC_PRER, RTC_PRER_PREDIV_A_SHIFT, and RTC_PRER_PREDIV_S_MASK.

◆ rtc_set_wakeup_time()

void rtc_set_wakeup_time ( uint16_t  wkup_time,
uint8_t  rtc_cr_wucksel 
)

Sets the wakeup time auto-reload value.

Definition at line 95 of file rtc_common_l1f024.c.

References RTC_CR, RTC_CR_WUCLKSEL_MASK, RTC_CR_WUCLKSEL_SHIFT, RTC_CR_WUTE, RTC_ISR, RTC_ISR_WUTWF, and RTC_WUTR.

◆ rtc_time_set_hour()

void rtc_time_set_hour ( uint8_t  hour,
bool  use_am_notation 
)

Sets the RTC BCD time hour value.

Requires unlocking the RTC write-protection (RTC_WPR)

Pass true to use_am_notation to use 24-hour input time; pass false to use_am_notation to use 12-hour (AM/PM) input time

Definition at line 287 of file rtc_common_l1f024.c.

References _rtc_dec_to_bcd(), RTC_TR, RTC_TR_HT_MASK, RTC_TR_HT_SHIFT, RTC_TR_HU_MASK, RTC_TR_HU_SHIFT, and RTC_TR_PM.

Referenced by rtc_time_set_time().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ rtc_time_set_minute()

void rtc_time_set_minute ( uint8_t  minute)

Sets the RTC BCD time minute value.

Requires unlocking the RTC write-protection (RTC_WPR)

Definition at line 306 of file rtc_common_l1f024.c.

References _rtc_dec_to_bcd(), RTC_TR, RTC_TR_MNT_MASK, RTC_TR_MNT_SHIFT, RTC_TR_MNU_MASK, and RTC_TR_MNU_SHIFT.

Referenced by rtc_time_set_time().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ rtc_time_set_second()

void rtc_time_set_second ( uint8_t  second)

Sets the RTC BCD time second value.

Requires unlocking the RTC write-protection (RTC_WPR)

Definition at line 319 of file rtc_common_l1f024.c.

References _rtc_dec_to_bcd(), RTC_TR, RTC_TR_ST_MASK, RTC_TR_ST_SHIFT, RTC_TR_SU_MASK, and RTC_TR_SU_SHIFT.

Referenced by rtc_time_set_time().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ rtc_time_set_time()

void rtc_time_set_time ( uint8_t  hour,
uint8_t  minute,
uint8_t  second,
bool  use_am_notation 
)

Sets the RTC BCD time.

Requires unlocking the RTC write-protection (RTC_WPR)

Definition at line 332 of file rtc_common_l1f024.c.

References rtc_time_set_hour(), rtc_time_set_minute(), and rtc_time_set_second().

Here is the call graph for this function:

◆ rtc_unlock()

void rtc_unlock ( void  )

Unlock write access to the RTC registers.

Definition at line 76 of file rtc_common_l1f024.c.

References RTC_WPR.

◆ rtc_wait_for_init_ready()

void rtc_wait_for_init_ready ( void  )

Waits infinitely for initialization flag to be set in RTC_ISR.

Requires unlocking backup domain write protection (PWR_CR_DBP)

Definition at line 165 of file rtc_common_l1f024.c.

References rtc_init_flag_is_ready().

Here is the call graph for this function:

◆ rtc_wait_for_synchro()

void rtc_wait_for_synchro ( void  )

Wait for RTC registers to be synchronised with the APB1 bus.

Time and Date are accessed through shadow registers which must be synchronized

Definition at line 58 of file rtc_common_l1f024.c.

References RTC_ISR, RTC_ISR_RSF, and RTC_WPR.