STM32F4xx HAL Driver master
STM32CubeF4 HAL / LL Drivers API Reference
Loading...
Searching...
No Matches
stm32f4xx_hal_rtc.c File Reference

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

#include "stm32f4xx_hal.h"
Include dependency graph for stm32f4xx_hal_rtc.c:

Go to the source code of this file.

Detailed Description

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

Author
MCD Application Team
  • Initialization and de-initialization functions
  • Calendar (Time and Date) configuration functions
  • Alarms (Alarm A and Alarm B) configuration functions
  • Peripheral Control functions
  • Peripheral State functions
Attention

Copyright (c) 2016 STMicroelectronics. All rights reserved.

This software is licensed under terms that can be found in the LICENSE file in the root directory of this software component. If no LICENSE file comes with this software, it is provided AS-IS.

==============================================================================
             ##### RTC and 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, BKP 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 operating even when the main digital supply (VDD) is turned
     off, the VBAT pin powers the following blocks:
  (#) The RTC
  (#) The LSE oscillator
  (#) The BKP 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 pins 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 pins 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 BKP SRAM is not affected by this reset. The only way to reset the BKP
     SRAM 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).
  (#) 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 BKP 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
      __HAL_RCC_PWR_CLK_ENABLE() macro.
  (+) Enable access to RTC domain using the HAL_PWR_EnableBkUpAccess() function.
  (+) Select the RTC clock source using the __HAL_RCC_RTC_CONFIG() macro.
  (+) Enable RTC Clock using the __HAL_RCC_RTC_ENABLE() macro.

==============================================================================
                      ##### How to use this 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 HAL_RTC_Init() function.

*** Time and Date configuration ***
===================================
[..]
  (+) To configure the RTC Calendar (Time and Date) use the HAL_RTC_SetTime()
      and HAL_RTC_SetDate() functions.
  (+) To read the RTC Calendar, use the HAL_RTC_GetTime() and HAL_RTC_GetDate()
      functions.
  (+) To manage the RTC summer or winter time change, use the following
      functions:
      (++) HAL_RTC_DST_Add1Hour() or HAL_RTC_DST_Sub1Hour to add or subtract
           1 hour from the calendar time.
      (++) HAL_RTC_DST_SetStoreOperation() or HAL_RTC_DST_ClearStoreOperation
           to memorize whether the time change has been performed or not.

*** Alarm configuration ***
===========================
[..]
  (+) To configure the RTC Alarm use the HAL_RTC_SetAlarm() function.
      You can also configure the RTC Alarm with interrupt mode using the
      HAL_RTC_SetAlarm_IT() function.
  (+) To read the RTC Alarm, use the HAL_RTC_GetAlarm() 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 timestamp event detection.
     These RTC alternate functions can wake up the system from the Stop and
     Standby low power 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.

*** Callback registration ***
=============================================
[..]
When the compilation define USE_HAL_RTC_REGISTER_CALLBACKS is set to 0 or
not defined, the callback registration feature is not available and all
callbacks are set to the corresponding weak functions.
This is the recommended configuration in order to optimize memory/code
consumption footprint/performances.
[..]
The compilation define  USE_HAL_RTC_REGISTER_CALLBACKS when set to 1
allows the user to configure dynamically the driver callbacks.
Use Function HAL_RTC_RegisterCallback() to register an interrupt callback.
[..]
Function HAL_RTC_RegisterCallback() allows to register following callbacks:
  (+) AlarmAEventCallback          : RTC Alarm A Event callback.
  (+) AlarmBEventCallback          : RTC Alarm B Event callback.
  (+) TimeStampEventCallback       : RTC Timestamp Event callback.
  (+) WakeUpTimerEventCallback     : RTC WakeUpTimer Event callback.
  (+) Tamper1EventCallback         : RTC Tamper 1 Event callback.
  (+) Tamper2EventCallback         : RTC Tamper 2 Event callback. (*)
  (+) MspInitCallback              : RTC MspInit callback.
  (+) MspDeInitCallback            : RTC MspDeInit callback.

(*) value not applicable to all devices.
[..]
This function takes as parameters the HAL peripheral handle, the Callback ID
and a pointer to the user callback function.
[..]
Use function HAL_RTC_UnRegisterCallback() to reset a callback to the default
weak function.
HAL_RTC_UnRegisterCallback() takes as parameters the HAL peripheral handle,
and the Callback ID.
This function allows to reset following callbacks:
  (+) AlarmAEventCallback          : RTC Alarm A Event callback.
  (+) AlarmBEventCallback          : RTC Alarm B Event callback.
  (+) TimeStampEventCallback       : RTC Timestamp Event callback.
  (+) WakeUpTimerEventCallback     : RTC WakeUpTimer Event callback.
  (+) Tamper1EventCallback         : RTC Tamper 1 Event callback.
  (+) Tamper2EventCallback         : RTC Tamper 2 Event callback. (*)
  (+) MspInitCallback              : RTC MspInit callback.
  (+) MspDeInitCallback            : RTC MspDeInit callback.

(*) value not applicable to all devices.
[..]
By default, after the HAL_RTC_Init() and when the state is HAL_RTC_STATE_RESET,
all callbacks are set to the corresponding weak functions:
examples AlarmAEventCallback(), TimeStampEventCallback().
Exception done for MspInit() and MspDeInit() callbacks that are reset to the
legacy weak function in the HAL_RTC_Init()/HAL_RTC_DeInit() only when these
callbacks are null (not registered beforehand).
If not, MspInit() or MspDeInit() are not null, HAL_RTC_Init()/HAL_RTC_DeInit()
keep and use the user MspInit()/MspDeInit() callbacks (registered beforehand).
[..]
Callbacks can be registered/unregistered in HAL_RTC_STATE_READY state only.
Exception done for MspInit() and MspDeInit() that can be registered/unregistered
in HAL_RTC_STATE_READY or HAL_RTC_STATE_RESET state.
Thus registered (user) MspInit()/MspDeInit() callbacks can be used during the
Init/DeInit.
In that case first register the MspInit()/MspDeInit() user callbacks using
HAL_RTC_RegisterCallback() before calling HAL_RTC_DeInit() or HAL_RTC_Init()
functions.

Definition in file stm32f4xx_hal_rtc.c.