Macros | Functions
stm32f4xx_rtc.c File Reference

This file provides firmware functions to manage the following functionalities of the Real-Time Clock (RTC) peripheral: More...

#include "stm32f4xx_rtc.h"
Include dependency graph for stm32f4xx_rtc.c:

Go to the source code of this file.

Macros

#define INITMODE_TIMEOUT   ((uint32_t) 0x00010000)
 
#define RECALPF_TIMEOUT   ((uint32_t) 0x00020000)
 
#define RTC_DR_RESERVED_MASK   ((uint32_t)0x00FFFF3F)
 
#define RTC_FLAGS_MASK
 
#define RTC_INIT_MASK   ((uint32_t)0xFFFFFFFF)
 
#define RTC_RSF_MASK   ((uint32_t)0xFFFFFF5F)
 
#define RTC_TR_RESERVED_MASK   ((uint32_t)0x007F7F7F)
 
#define SHPF_TIMEOUT   ((uint32_t) 0x00001000)
 
#define SYNCHRO_TIMEOUT   ((uint32_t) 0x00020000)
 

Functions

ErrorStatus RTC_AlarmCmd (uint32_t RTC_Alarm, FunctionalState NewState)
 Enables or disables the specified RTC Alarm. More...
 
void RTC_AlarmStructInit (RTC_AlarmTypeDef *RTC_AlarmStruct)
 Fills each RTC_AlarmStruct member with its default value (Time = 00h:00mn:00sec / Date = 1st day of the month/Mask = all fields are masked). More...
 
void RTC_AlarmSubSecondConfig (uint32_t RTC_Alarm, uint32_t RTC_AlarmSubSecondValue, uint32_t RTC_AlarmSubSecondMask)
 Configure the RTC AlarmA/B Sub seconds value and mask.*. More...
 
static uint8_t RTC_Bcd2ToByte (uint8_t Value)
 Convert from 2 digit BCD to Binary. More...
 
void RTC_BypassShadowCmd (FunctionalState NewState)
 Enables or Disables the Bypass Shadow feature. More...
 
static uint8_t RTC_ByteToBcd2 (uint8_t Value)
 Converts a 2 digit decimal to BCD format. More...
 
void RTC_CalibOutputCmd (FunctionalState NewState)
 Enables or disables the RTC clock to be output through the relative pin. More...
 
void RTC_CalibOutputConfig (uint32_t RTC_CalibOutput)
 Configure the Calibration Pinout (RTC_CALIB) Selection (1Hz or 512Hz). More...
 
void RTC_ClearFlag (uint32_t RTC_FLAG)
 Clears the RTC's pending flags. More...
 
void RTC_ClearITPendingBit (uint32_t RTC_IT)
 Clears the RTC's interrupt pending bits. More...
 
ErrorStatus RTC_CoarseCalibCmd (FunctionalState NewState)
 Enables or disables the Coarse calibration process. More...
 
ErrorStatus RTC_CoarseCalibConfig (uint32_t RTC_CalibSign, uint32_t Value)
 Configures the Coarse calibration parameters. More...
 
void RTC_DateStructInit (RTC_DateTypeDef *RTC_DateStruct)
 Fills each RTC_DateStruct member with its default value (Monday, January 01 xx00). More...
 
void RTC_DayLightSavingConfig (uint32_t RTC_DayLightSaving, uint32_t RTC_StoreOperation)
 Adds or substract one hour from the current time. More...
 
ErrorStatus RTC_DeInit (void)
 Deinitializes the RTC registers to their default reset values. More...
 
ErrorStatus RTC_EnterInitMode (void)
 Enters the RTC Initialization mode. More...
 
void RTC_ExitInitMode (void)
 Exits the RTC Initialization mode. More...
 
void RTC_GetAlarm (uint32_t RTC_Format, uint32_t RTC_Alarm, RTC_AlarmTypeDef *RTC_AlarmStruct)
 Get the RTC Alarm value and masks. More...
 
uint32_t RTC_GetAlarmSubSecond (uint32_t RTC_Alarm)
 Gets the RTC Alarm Sub seconds value. More...
 
void RTC_GetDate (uint32_t RTC_Format, RTC_DateTypeDef *RTC_DateStruct)
 Get the RTC current date. More...
 
FlagStatus RTC_GetFlagStatus (uint32_t RTC_FLAG)
 Checks whether the specified RTC flag is set or not. More...
 
ITStatus RTC_GetITStatus (uint32_t RTC_IT)
 Checks whether the specified RTC interrupt has occurred or not. More...
 
uint32_t RTC_GetStoreOperation (void)
 Returns the RTC Day Light Saving stored operation. More...
 
uint32_t RTC_GetSubSecond (void)
 Gets the RTC current Calendar Sub seconds value. More...
 
void RTC_GetTime (uint32_t RTC_Format, RTC_TimeTypeDef *RTC_TimeStruct)
 Get the RTC current Time. More...
 
void RTC_GetTimeStamp (uint32_t RTC_Format, RTC_TimeTypeDef *RTC_StampTimeStruct, RTC_DateTypeDef *RTC_StampDateStruct)
 Get the RTC TimeStamp value and masks. More...
 
uint32_t RTC_GetTimeStampSubSecond (void)
 Get the RTC timestamp Sub seconds value. More...
 
uint32_t RTC_GetWakeUpCounter (void)
 Returns the RTC WakeUp timer counter value. More...
 
ErrorStatus RTC_Init (RTC_InitTypeDef *RTC_InitStruct)
 Initializes the RTC registers according to the specified parameters in RTC_InitStruct. More...
 
void RTC_ITConfig (uint32_t RTC_IT, FunctionalState NewState)
 Enables or disables the specified RTC interrupts. More...
 
void RTC_OutputConfig (uint32_t RTC_Output, uint32_t RTC_OutputPolarity)
 Configures the RTC output source (AFO_ALARM). More...
 
void RTC_OutputTypeConfig (uint32_t RTC_OutputType)
 Configures the RTC Output Pin mode. More...
 
uint32_t RTC_ReadBackupRegister (uint32_t RTC_BKP_DR)
 Reads data from the specified RTC Backup data Register. More...
 
ErrorStatus RTC_RefClockCmd (FunctionalState NewState)
 Enables or disables the RTC reference clock detection. More...
 
void RTC_SetAlarm (uint32_t RTC_Format, uint32_t RTC_Alarm, RTC_AlarmTypeDef *RTC_AlarmStruct)
 Set the specified RTC Alarm. More...
 
ErrorStatus RTC_SetDate (uint32_t RTC_Format, RTC_DateTypeDef *RTC_DateStruct)
 Set the RTC current date. More...
 
ErrorStatus RTC_SetTime (uint32_t RTC_Format, RTC_TimeTypeDef *RTC_TimeStruct)
 Set the RTC current time. More...
 
void RTC_SetWakeUpCounter (uint32_t RTC_WakeUpCounter)
 Configures the RTC Wakeup counter. More...
 
ErrorStatus RTC_SmoothCalibConfig (uint32_t RTC_SmoothCalibPeriod, uint32_t RTC_SmoothCalibPlusPulses, uint32_t RTC_SmouthCalibMinusPulsesValue)
 Configures the Smooth Calibration Settings. More...
 
void RTC_StructInit (RTC_InitTypeDef *RTC_InitStruct)
 Fills each RTC_InitStruct member with its default value. More...
 
ErrorStatus RTC_SynchroShiftConfig (uint32_t RTC_ShiftAdd1S, uint32_t RTC_ShiftSubFS)
 Configures the Synchronization Shift Control Settings. More...
 
void RTC_TamperCmd (uint32_t RTC_Tamper, FunctionalState NewState)
 Enables or Disables the Tamper detection. More...
 
void RTC_TamperFilterConfig (uint32_t RTC_TamperFilter)
 Configures the Tampers Filter. More...
 
void RTC_TamperPinSelection (uint32_t RTC_TamperPin)
 Selects the RTC Tamper Pin. More...
 
void RTC_TamperPinsPrechargeDuration (uint32_t RTC_TamperPrechargeDuration)
 Configures the Tampers Pins input Precharge Duration. More...
 
void RTC_TamperPullUpCmd (FunctionalState NewState)
 Enables or Disables the Precharge of Tamper pin. More...
 
void RTC_TamperSamplingFreqConfig (uint32_t RTC_TamperSamplingFreq)
 Configures the Tampers Sampling Frequency. More...
 
void RTC_TamperTriggerConfig (uint32_t RTC_Tamper, uint32_t RTC_TamperTrigger)
 Configures the select Tamper pin edge. More...
 
void RTC_TimeStampCmd (uint32_t RTC_TimeStampEdge, FunctionalState NewState)
 Enables or Disables the RTC TimeStamp functionality with the specified time stamp pin stimulating edge. More...
 
void RTC_TimeStampOnTamperDetectionCmd (FunctionalState NewState)
 Enables or Disables the TimeStamp on Tamper Detection Event. More...
 
void RTC_TimeStampPinSelection (uint32_t RTC_TimeStampPin)
 Selects the RTC TimeStamp Pin. More...
 
void RTC_TimeStructInit (RTC_TimeTypeDef *RTC_TimeStruct)
 Fills each RTC_TimeStruct member with its default value (Time = 00h:00min:00sec). More...
 
ErrorStatus RTC_WaitForSynchro (void)
 Waits until the RTC Time and Date registers (RTC_TR and RTC_DR) are synchronized with RTC APB clock. More...
 
void RTC_WakeUpClockConfig (uint32_t RTC_WakeUpClock)
 Configures the RTC Wakeup clock source. More...
 
ErrorStatus RTC_WakeUpCmd (FunctionalState NewState)
 Enables or Disables the RTC WakeUp timer. More...
 
void RTC_WriteBackupRegister (uint32_t RTC_BKP_DR, uint32_t Data)
 Writes a data in a specified RTC Backup data register. More...
 
void RTC_WriteProtectionCmd (FunctionalState NewState)
 Enables or disables the RTC registers write protection. More...
 

Detailed Description

This file provides firmware functions to manage the following functionalities of the Real-Time Clock (RTC) peripheral:

Author
MCD Application Team
Version
V1.1.0
Date
11-January-2013
  • Initialization
  • Calendar (Time and Date) configuration
  • Alarms (Alarm A and Alarm B) configuration
  • WakeUp Timer configuration
  • Daylight Saving configuration
  • Output pin Configuration
  • Coarse digital Calibration configuration
  • Smooth digital Calibration configuration
  • TimeStamp configuration
  • Tampers configuration
  • Backup Data Registers configuration
  • Shift control synchronisation
  • RTC Tamper and TimeStamp Pins Selection and Output Type Config configuration
  • Interrupts and flags management
 ===================================================================
              ##### Backup Domain Operating Condition #####
 ===================================================================
 [..] The real-time clock (RTC), the RTC backup registers, and the backup 
      SRAM (BKP SRAM) can be powered from the VBAT voltage when the main 
      VDD supply is powered off.
      To retain the content of the RTC backup registers, backup SRAM, and supply 
      the RTC when VDD is turned off, VBAT pin can be connected to an optional 
      standby voltage supplied by a battery or by another source.

 [..] To allow the RTC to operate even when the main digital supply (VDD) is turned
      off, the VBAT pin powers the following blocks:
   (#) The RTC
   (#) The LSE oscillator
   (#) The backup SRAM when the low power backup regulator is enabled
   (#) PC13 to PC15 I/Os, plus PI8 I/O (when available)
  
 [..] When the backup domain is supplied by VDD (analog switch connected to VDD),
      the following functions are available:
   (#) PC14 and PC15 can be used as either GPIO or LSE pins
   (#) PC13 can be used as a GPIO or as the RTC_AF1 pin
   (#) PI8 can be used as a GPIO or as the RTC_AF2 pin
  
 [..] When the backup domain is supplied by VBAT (analog switch connected to VBAT 
      because VDD is not present), the following functions are available:
   (#) PC14 and PC15 can be used as LSE pins only
   (#) PC13 can be used as the RTC_AF1 pin 
   (#) PI8 can be used as the RTC_AF2 pin
  
            
                   ##### Backup Domain Reset #####
 ===================================================================
 [..] The backup domain reset sets all RTC registers and the RCC_BDCR register 
      to their reset values. The BKPSRAM is not affected by this reset. The only
      way of resetting the BKPSRAM is through the Flash interface by requesting 
      a protection level change from 1 to 0.
 [..] A backup domain reset is generated when one of the following events occurs:
   (#) Software reset, triggered by setting the BDRST bit in the 
       RCC Backup domain control register (RCC_BDCR). You can use the
       RCC_BackupResetCmd().
   (#) VDD or VBAT power on, if both supplies have previously been powered off.
  

                   ##### Backup Domain Access #####
 ===================================================================
 [..] After reset, the backup domain (RTC registers, RTC backup data 
      registers and backup SRAM) is protected against possible unwanted write 
      accesses. 
 [..] To enable access to the RTC Domain and RTC registers, proceed as follows:
   (+) Enable the Power Controller (PWR) APB1 interface clock using the
       RCC_APB1PeriphClockCmd() function.
   (+) Enable access to RTC domain using the PWR_BackupAccessCmd() function.
   (+) Select the RTC clock source using the RCC_RTCCLKConfig() function.
   (+) Enable RTC Clock using the RCC_RTCCLKCmd() function.
  
  
                  ##### How to use RTC Driver #####
 ===================================================================
 [..] 
   (+) Enable the RTC domain access (see description in the section above)
   (+) Configure the RTC Prescaler (Asynchronous and Synchronous) and RTC hour 
       format using the RTC_Init() function.
  
 *** Time and Date configuration ***
 ===================================
 [..] 
   (+) To configure the RTC Calendar (Time and Date) use the RTC_SetTime()
       and RTC_SetDate() functions.
   (+) To read the RTC Calendar, use the RTC_GetTime() and RTC_GetDate() functions.
   (+) Use the RTC_DayLightSavingConfig() function to add or sub one
       hour to the RTC Calendar.    
  
 *** Alarm configuration ***
 ===========================
 [..]
   (+) To configure the RTC Alarm use the RTC_SetAlarm() function.
   (+) Enable the selected RTC Alarm using the RTC_AlarmCmd() function
   (+) To read the RTC Alarm, use the RTC_GetAlarm() function.
   (+) To read the RTC alarm SubSecond, use the RTC_GetAlarmSubSecond() function.
  
 *** RTC Wakeup configuration ***
 ================================
 [..] 
   (+) Configure the RTC Wakeup Clock source use the RTC_WakeUpClockConfig()
       function.
   (+) Configure the RTC WakeUp Counter using the RTC_SetWakeUpCounter() function  
   (+) Enable the RTC WakeUp using the RTC_WakeUpCmd() function  
   (+) To read the RTC WakeUp Counter register, use the RTC_GetWakeUpCounter() 
       function.
  
 *** Outputs configuration ***
 =============================
 [..] The RTC has 2 different outputs:
   (+) AFO_ALARM: this output is used to manage the RTC Alarm A, Alarm B
       and WaKeUp signals. To output the selected RTC signal on RTC_AF1 pin, use the 
       RTC_OutputConfig() function.                
   (+) AFO_CALIB: this output is 512Hz signal or 1Hz. To output the RTC Clock on 
       RTC_AF1 pin, use the RTC_CalibOutputCmd() function.
  
 *** Smooth digital Calibration configuration ***
 ================================================    
 [..]
   (+) Configure the RTC Original Digital Calibration Value and the corresponding
       calibration cycle period (32s,16s and 8s) using the RTC_SmoothCalibConfig() 
       function.
  
 *** Coarse digital Calibration configuration ***
 ================================================
 [..]
   (+) Configure the RTC Coarse Calibration Value and the corresponding
       sign using the RTC_CoarseCalibConfig() function.
   (+) Enable the RTC Coarse Calibration using the RTC_CoarseCalibCmd() function  
  
 *** TimeStamp configuration ***
 ===============================
 [..]
   (+) Configure the RTC_AF1 trigger and enables the RTC TimeStamp using the RTC
      _TimeStampCmd() function.
   (+) To read the RTC TimeStamp Time and Date register, use the RTC_GetTimeStamp()
       function.
   (+) To read the RTC TimeStamp SubSecond register, use the 
       RTC_GetTimeStampSubSecond() function.
   (+) The TAMPER1 alternate function can be mapped either to RTC_AF1(PC13)
       or RTC_AF2 (PI8) depending on the value of TAMP1INSEL bit in 
       RTC_TAFCR register. You can use the  RTC_TamperPinSelection() function to
       select the corresponding pin.     
  
 *** Tamper configuration ***
 ============================
 [..]
   (+) Enable the RTC Tamper using the RTC_TamperCmd() function.
   (+) Configure the Tamper filter count using RTC_TamperFilterConfig()
       function. 
   (+) Configure the RTC Tamper trigger Edge or Level according to the Tamper 
       filter (if equal to 0 Edge else Level) value using the RTC_TamperConfig() 
       function.
   (+) Configure the Tamper sampling frequency using RTC_TamperSamplingFreqConfig()
       function.
   (+) Configure the Tamper precharge or discharge duration using 
       RTC_TamperPinsPrechargeDuration() function.
   (+) Enable the Tamper Pull-UP using RTC_TamperPullUpDisableCmd() function.
   (+) Enable the Time stamp on Tamper detection event using  
       TC_TSOnTamperDetecCmd() function.
   (+) The TIMESTAMP alternate function can be mapped to either RTC_AF1 
       or RTC_AF2 depending on the value of the TSINSEL bit in the RTC_TAFCR 
       register. You can use the  RTC_TimeStampPinSelection() function to select 
       the corresponding pin. 
  
 *** Backup Data Registers configuration ***
 ===========================================
 [..]
   (+) To write to the RTC Backup Data registers, use the RTC_WriteBackupRegister()
       function.  
   (+) To read the RTC Backup Data registers, use the RTC_ReadBackupRegister()
       function.
   

                  ##### RTC and low power modes #####
 ===================================================================
 [..] The MCU can be woken up from a low power mode by an RTC alternate 
      function.
 [..] The RTC alternate functions are the RTC alarms (Alarm A and Alarm B), 
      RTC wakeup, RTC tamper event detection and RTC time stamp event detection.
      These RTC alternate functions can wake up the system from the Stop and 
      Standby lowpower modes.
 [..] The system can also wake up from low power modes without depending 
      on an external interrupt (Auto-wakeup mode), by using the RTC alarm 
      or the RTC wakeup events.
 [..] The RTC provides a programmable time base for waking up from the 
      Stop or Standby mode at regular intervals.
      Wakeup from STOP and Standby modes is possible only when the RTC clock source
      is LSE or LSI.
  

          ##### Selection of RTC_AF1 alternate functions #####
 ===================================================================
 [..] The RTC_AF1 pin (PC13) can be used for the following purposes:
   (+) AFO_ALARM output
   (+) AFO_CALIB output
   (+) AFI_TAMPER
   (+) AFI_TIMESTAMP
 
 [..]   
   +-------------------------------------------------------------------------------------------------------------+
   |     Pin         |AFO_ALARM |AFO_CALIB |AFI_TAMPER |AFI_TIMESTAMP | TAMP1INSEL |   TSINSEL    |ALARMOUTTYPE  |
   |  configuration  | ENABLED  | ENABLED  |  ENABLED  |   ENABLED    |TAMPER1 pin |TIMESTAMP pin |  AFO_ALARM   |
   |  and function   |          |          |           |              | selection  |  selection   |Configuration |
   |-----------------|----------|----------|-----------|--------------|------------|--------------|--------------|
   |   Alarm out     |          |          |           |              |    Don't   |     Don't    |              |
   |   output OD     |     1    |Don't care|Don't care | Don't care   |    care    |     care     |      0       |
   |-----------------|----------|----------|-----------|--------------|------------|--------------|--------------|
   |   Alarm out     |          |          |           |              |    Don't   |     Don't    |              |
   |   output PP     |     1    |Don't care|Don't care | Don't care   |    care    |     care     |      1       |
   |-----------------|----------|----------|-----------|--------------|------------|--------------|--------------|
   | Calibration out |          |          |           |              |    Don't   |     Don't    |              |
   |   output PP     |     0    |    1     |Don't care | Don't care   |    care    |     care     |  Don't care  |
   |-----------------|----------|----------|-----------|--------------|------------|--------------|--------------|
   |  TAMPER input   |          |          |           |              |            |     Don't    |              |
   |   floating      |     0    |    0     |     1     |      0       |      0     |     care     |  Don't care  |
   |-----------------|----------|----------|-----------|--------------|------------|--------------|--------------|
   |  TIMESTAMP and  |          |          |           |              |            |              |              |
   |  TAMPER input   |     0    |    0     |     1     |      1       |      0     |      0       |  Don't care  |
   |   floating      |          |          |           |              |            |              |              |
   |-----------------|----------|----------|-----------|--------------|------------|--------------|--------------|
   | TIMESTAMP input |          |          |           |              |    Don't   |              |              |
   |    floating     |     0    |    0     |     0     |      1       |    care    |      0       |  Don't care  |
   |-----------------|----------|----------|-----------|--------------|------------|--------------|--------------|
   |  Standard GPIO  |     0    |    0     |     0     |      0       | Don't care |  Don't care  |  Don't care  |
   +-------------------------------------------------------------------------------------------------------------+

            
        #####  Selection of RTC_AF2 alternate functions #####
 ===================================================================
 [..] The RTC_AF2 pin (PI8) can be used for the following purposes:
   (+) AFI_TAMPER
   (+) AFI_TIMESTAMP
 [..]
   +---------------------------------------------------------------------------------------+
   |     Pin         |AFI_TAMPER |AFI_TIMESTAMP | TAMP1INSEL |   TSINSEL    |ALARMOUTTYPE  |
   |  configuration  |  ENABLED  |   ENABLED    |TAMPER1 pin |TIMESTAMP pin |  AFO_ALARM   |
   |  and function   |           |              | selection  |  selection   |Configuration |
   |-----------------|-----------|--------------|------------|--------------|--------------|
   |  TAMPER input   |           |              |            |     Don't    |              |
   |   floating      |     1     |      0       |      1     |     care     |  Don't care  |
   |-----------------|-----------|--------------|------------|--------------|--------------|
   |  TIMESTAMP and  |           |              |            |              |              |
   |  TAMPER input   |     1     |      1       |      1     |      1       |  Don't care  |
   |   floating      |           |              |            |              |              |
   |-----------------|-----------|--------------|------------|--------------|--------------|
   | TIMESTAMP input |           |              |    Don't   |              |              |
   |    floating     |     0     |      1       |    care    |      1       |  Don't care  |
   |-----------------|-----------|--------------|------------|--------------|--------------|
   |  Standard GPIO  |     0     |      0       | Don't care |  Don't care  |  Don't care  |
   +---------------------------------------------------------------------------------------+   
@attention

<h2><center>&copy; COPYRIGHT 2013 STMicroelectronics</center></h2>

Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
You may not use this file except in compliance with the License.
You may obtain a copy of the License at:

       http://www.st.com/software_license_agreement_liberty_v2

Unless required by applicable law or agreed to in writing, software 
distributed under the License is distributed on an "AS IS" BASIS, 
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

Definition in file stm32f4xx_rtc.c.



rosflight_firmware
Author(s): Daniel Koch , James Jackson
autogenerated on Thu Apr 15 2021 05:07:53