You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

128 lines
3.1 KiB

4 years ago
  1. /**
  2. ******************************************************************************
  3. * @file rtc.c
  4. * @brief This file provides code for the configuration
  5. * of the RTC instances.
  6. ******************************************************************************
  7. * @attention
  8. *
  9. * <h2><center>&copy; Copyright (c) 2022 STMicroelectronics.
  10. * All rights reserved.</center></h2>
  11. *
  12. * This software component is licensed by ST under BSD 3-Clause license,
  13. * the "License"; You may not use this file except in compliance with the
  14. * License. You may obtain a copy of the License at:
  15. * opensource.org/licenses/BSD-3-Clause
  16. *
  17. ******************************************************************************
  18. */
  19. /* Includes ------------------------------------------------------------------*/
  20. #include "rtc.h"
  21. /* USER CODE BEGIN 0 */
  22. /* USER CODE END 0 */
  23. RTC_HandleTypeDef hrtc;
  24. /* RTC init function */
  25. void MX_RTC_Init(void)
  26. {
  27. /* USER CODE BEGIN RTC_Init 0 */
  28. /* USER CODE END RTC_Init 0 */
  29. RTC_TimeTypeDef sTime = {0};
  30. RTC_DateTypeDef DateToUpdate = {0};
  31. /* USER CODE BEGIN RTC_Init 1 */
  32. /* USER CODE END RTC_Init 1 */
  33. /** Initialize RTC Only
  34. */
  35. hrtc.Instance = RTC;
  36. hrtc.Init.AsynchPrediv = RTC_AUTO_1_SECOND;
  37. hrtc.Init.OutPut = RTC_OUTPUTSOURCE_NONE;
  38. if (HAL_RTC_Init(&hrtc) != HAL_OK)
  39. {
  40. Error_Handler();
  41. }
  42. /* USER CODE BEGIN Check_RTC_BKUP */
  43. /* USER CODE END Check_RTC_BKUP */
  44. /** Initialize RTC and set the Time and Date
  45. */
  46. sTime.Hours = 0x0;
  47. sTime.Minutes = 0x0;
  48. sTime.Seconds = 0x0;
  49. if (HAL_RTC_SetTime(&hrtc, &sTime, RTC_FORMAT_BCD) != HAL_OK)
  50. {
  51. Error_Handler();
  52. }
  53. DateToUpdate.WeekDay = RTC_WEEKDAY_MONDAY;
  54. DateToUpdate.Month = RTC_MONTH_JANUARY;
  55. DateToUpdate.Date = 0x1;
  56. DateToUpdate.Year = 0x0;
  57. if (HAL_RTC_SetDate(&hrtc, &DateToUpdate, RTC_FORMAT_BCD) != HAL_OK)
  58. {
  59. Error_Handler();
  60. }
  61. /* USER CODE BEGIN RTC_Init 2 */
  62. /* USER CODE END RTC_Init 2 */
  63. }
  64. void HAL_RTC_MspInit(RTC_HandleTypeDef* rtcHandle)
  65. {
  66. if(rtcHandle->Instance==RTC)
  67. {
  68. /* USER CODE BEGIN RTC_MspInit 0 */
  69. /* USER CODE END RTC_MspInit 0 */
  70. HAL_PWR_EnableBkUpAccess();
  71. /* Enable BKP CLK enable for backup registers */
  72. __HAL_RCC_BKP_CLK_ENABLE();
  73. /* RTC clock enable */
  74. __HAL_RCC_RTC_ENABLE();
  75. /* RTC interrupt Init */
  76. HAL_NVIC_SetPriority(RTC_IRQn, 0, 0);
  77. HAL_NVIC_EnableIRQ(RTC_IRQn);
  78. /* USER CODE BEGIN RTC_MspInit 1 */
  79. /* USER CODE END RTC_MspInit 1 */
  80. }
  81. }
  82. void HAL_RTC_MspDeInit(RTC_HandleTypeDef* rtcHandle)
  83. {
  84. if(rtcHandle->Instance==RTC)
  85. {
  86. /* USER CODE BEGIN RTC_MspDeInit 0 */
  87. /* USER CODE END RTC_MspDeInit 0 */
  88. /* Peripheral clock disable */
  89. __HAL_RCC_RTC_DISABLE();
  90. /* RTC interrupt Deinit */
  91. HAL_NVIC_DisableIRQ(RTC_IRQn);
  92. /* USER CODE BEGIN RTC_MspDeInit 1 */
  93. /* USER CODE END RTC_MspDeInit 1 */
  94. }
  95. }
  96. /* USER CODE BEGIN 1 */
  97. /* USER CODE END 1 */
  98. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/