rtc.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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) 2022 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. /* USER CODE BEGIN RTC_Init 2 */
  47. /* USER CODE END RTC_Init 2 */
  48. }
  49. void HAL_RTC_MspInit(RTC_HandleTypeDef* rtcHandle)
  50. {
  51. RCC_PeriphCLKInitTypeDef PeriphClkInit = {0};
  52. if(rtcHandle->Instance==RTC)
  53. {
  54. /* USER CODE BEGIN RTC_MspInit 0 */
  55. /* USER CODE END RTC_MspInit 0 */
  56. /** Initializes the peripherals clock
  57. */
  58. PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_RTC;
  59. PeriphClkInit.RTCClockSelection = RCC_RTCCLKSOURCE_LSI;
  60. if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK)
  61. {
  62. Error_Handler();
  63. }
  64. /* RTC clock enable */
  65. __HAL_RCC_RTC_ENABLE();
  66. /* USER CODE BEGIN RTC_MspInit 1 */
  67. /* USER CODE END RTC_MspInit 1 */
  68. }
  69. }
  70. void HAL_RTC_MspDeInit(RTC_HandleTypeDef* rtcHandle)
  71. {
  72. if(rtcHandle->Instance==RTC)
  73. {
  74. /* USER CODE BEGIN RTC_MspDeInit 0 */
  75. /* USER CODE END RTC_MspDeInit 0 */
  76. /* Peripheral clock disable */
  77. __HAL_RCC_RTC_DISABLE();
  78. /* USER CODE BEGIN RTC_MspDeInit 1 */
  79. /* USER CODE END RTC_MspDeInit 1 */
  80. }
  81. }
  82. /* USER CODE BEGIN 1 */
  83. /* USER CODE END 1 */