rtc.c 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. /* USER CODE BEGIN Header */
  2. /**
  3. ******************************************************************************
  4. * @file rtc.c
  5. * @brief This file provides code for the configuration
  6. * of the RTC instances.
  7. ******************************************************************************
  8. * @attention
  9. *
  10. * Copyright (c) 2026 STMicroelectronics.
  11. * All rights reserved.
  12. *
  13. * This software is licensed under terms that can be found in the LICENSE file
  14. * in the root directory of this software component.
  15. * If no LICENSE file comes with this software, it is provided AS-IS.
  16. *
  17. ******************************************************************************
  18. */
  19. /* USER CODE END Header */
  20. /* Includes ------------------------------------------------------------------*/
  21. #include "rtc.h"
  22. /* USER CODE BEGIN 0 */
  23. /* USER CODE END 0 */
  24. RTC_HandleTypeDef hrtc;
  25. /* RTC init function */
  26. void MX_RTC_Init(void)
  27. {
  28. /* USER CODE BEGIN RTC_Init 0 */
  29. /* USER CODE END RTC_Init 0 */
  30. /* USER CODE BEGIN RTC_Init 1 */
  31. /* USER CODE END RTC_Init 1 */
  32. /** Initialize RTC Only
  33. */
  34. hrtc.Instance = RTC;
  35. hrtc.Init.AsynchPrediv = RTC_AUTO_1_SECOND;
  36. hrtc.Init.OutPut = RTC_OUTPUTSOURCE_ALARM;
  37. if (HAL_RTC_Init(&hrtc) != HAL_OK)
  38. {
  39. Error_Handler();
  40. }
  41. /* USER CODE BEGIN RTC_Init 2 */
  42. /* USER CODE END RTC_Init 2 */
  43. }
  44. void HAL_RTC_MspInit(RTC_HandleTypeDef* rtcHandle)
  45. {
  46. if(rtcHandle->Instance==RTC)
  47. {
  48. /* USER CODE BEGIN RTC_MspInit 0 */
  49. /* USER CODE END RTC_MspInit 0 */
  50. HAL_PWR_EnableBkUpAccess();
  51. /* Enable BKP CLK enable for backup registers */
  52. __HAL_RCC_BKP_CLK_ENABLE();
  53. /* RTC clock enable */
  54. __HAL_RCC_RTC_ENABLE();
  55. /* USER CODE BEGIN RTC_MspInit 1 */
  56. /* USER CODE END RTC_MspInit 1 */
  57. }
  58. }
  59. void HAL_RTC_MspDeInit(RTC_HandleTypeDef* rtcHandle)
  60. {
  61. if(rtcHandle->Instance==RTC)
  62. {
  63. /* USER CODE BEGIN RTC_MspDeInit 0 */
  64. /* USER CODE END RTC_MspDeInit 0 */
  65. /* Peripheral clock disable */
  66. __HAL_RCC_RTC_DISABLE();
  67. /* USER CODE BEGIN RTC_MspDeInit 1 */
  68. /* USER CODE END RTC_MspDeInit 1 */
  69. }
  70. }
  71. /* USER CODE BEGIN 1 */
  72. /* USER CODE END 1 */