rtc.c 2.5 KB

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