rtc.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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) 2024 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.HourFormat = RTC_HOURFORMAT_24;
  36. hrtc.Init.AsynchPrediv = 127;
  37. hrtc.Init.SynchPrediv = 255;
  38. hrtc.Init.OutPut = RTC_OUTPUT_DISABLE;
  39. hrtc.Init.OutPutRemap = RTC_OUTPUT_REMAP_NONE;
  40. hrtc.Init.OutPutPolarity = RTC_OUTPUT_POLARITY_HIGH;
  41. hrtc.Init.OutPutType = RTC_OUTPUT_TYPE_OPENDRAIN;
  42. if (HAL_RTC_Init(&hrtc) != HAL_OK)
  43. {
  44. Error_Handler();
  45. }
  46. /** Enable the WakeUp
  47. */
  48. if (HAL_RTCEx_SetWakeUpTimer_IT(&hrtc, 0, RTC_WAKEUPCLOCK_CK_SPRE_16BITS) != HAL_OK)
  49. {
  50. Error_Handler();
  51. }
  52. /* USER CODE BEGIN RTC_Init 2 */
  53. /* USER CODE END RTC_Init 2 */
  54. }
  55. void HAL_RTC_MspInit(RTC_HandleTypeDef* rtcHandle)
  56. {
  57. RCC_PeriphCLKInitTypeDef PeriphClkInit = {0};
  58. if(rtcHandle->Instance==RTC)
  59. {
  60. /* USER CODE BEGIN RTC_MspInit 0 */
  61. /* USER CODE END RTC_MspInit 0 */
  62. /** Initializes the peripherals clock
  63. */
  64. PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_RTC;
  65. PeriphClkInit.RTCClockSelection = RCC_RTCCLKSOURCE_LSE;
  66. if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK)
  67. {
  68. Error_Handler();
  69. }
  70. /* RTC clock enable */
  71. __HAL_RCC_RTC_ENABLE();
  72. /* RTC interrupt Init */
  73. HAL_NVIC_SetPriority(RTC_WKUP_IRQn, 5, 0);
  74. HAL_NVIC_EnableIRQ(RTC_WKUP_IRQn);
  75. /* USER CODE BEGIN RTC_MspInit 1 */
  76. /* USER CODE END RTC_MspInit 1 */
  77. }
  78. }
  79. void HAL_RTC_MspDeInit(RTC_HandleTypeDef* rtcHandle)
  80. {
  81. if(rtcHandle->Instance==RTC)
  82. {
  83. /* USER CODE BEGIN RTC_MspDeInit 0 */
  84. /* USER CODE END RTC_MspDeInit 0 */
  85. /* Peripheral clock disable */
  86. __HAL_RCC_RTC_DISABLE();
  87. /* RTC interrupt Deinit */
  88. HAL_NVIC_DisableIRQ(RTC_WKUP_IRQn);
  89. /* USER CODE BEGIN RTC_MspDeInit 1 */
  90. /* USER CODE END RTC_MspDeInit 1 */
  91. }
  92. }
  93. /* USER CODE BEGIN 1 */
  94. /* USER CODE END 1 */