rtc.c 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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. uint16_t ReadHeureMin(void){
  23. RTC_TimeTypeDef sTime;
  24. HAL_RTC_GetTime(&hrtc, &sTime,RTC_FORMAT_BCD);
  25. return sTime.Hours*60+sTime.Minutes;
  26. }
  27. HAL_StatusTypeDef WriteTime(RTC_TimeTypeDef *sTime,RTC_DateTypeDef *sDate){
  28. HAL_StatusTypeDef res;
  29. if (( res = HAL_RTC_SetTime(&hrtc, sTime, RTC_FORMAT_BCD)) != HAL_OK)
  30. return res;
  31. return HAL_RTC_SetDate(&hrtc, &sDate, RTC_FORMAT_BCD);
  32. }
  33. /* USER CODE END 0 */
  34. RTC_HandleTypeDef hrtc;
  35. /* RTC init function */
  36. void MX_RTC_Init(void)
  37. {
  38. /** Initialize RTC Only
  39. */
  40. hrtc.Instance = RTC;
  41. hrtc.Init.HourFormat = RTC_HOURFORMAT_24;
  42. hrtc.Init.AsynchPrediv = 127;
  43. hrtc.Init.SynchPrediv = 255;
  44. hrtc.Init.OutPut = RTC_OUTPUT_DISABLE;
  45. hrtc.Init.OutPutPolarity = RTC_OUTPUT_POLARITY_HIGH;
  46. hrtc.Init.OutPutType = RTC_OUTPUT_TYPE_OPENDRAIN;
  47. if (HAL_RTC_Init(&hrtc) != HAL_OK)
  48. {
  49. Error_Handler();
  50. }
  51. }
  52. void HAL_RTC_MspInit(RTC_HandleTypeDef* rtcHandle)
  53. {
  54. if(rtcHandle->Instance==RTC)
  55. {
  56. /* USER CODE BEGIN RTC_MspInit 0 */
  57. /* USER CODE END RTC_MspInit 0 */
  58. /* RTC clock enable */
  59. __HAL_RCC_RTC_ENABLE();
  60. /* USER CODE BEGIN RTC_MspInit 1 */
  61. /* USER CODE END RTC_MspInit 1 */
  62. }
  63. }
  64. void HAL_RTC_MspDeInit(RTC_HandleTypeDef* rtcHandle)
  65. {
  66. if(rtcHandle->Instance==RTC)
  67. {
  68. /* USER CODE BEGIN RTC_MspDeInit 0 */
  69. /* USER CODE END RTC_MspDeInit 0 */
  70. /* Peripheral clock disable */
  71. __HAL_RCC_RTC_DISABLE();
  72. /* USER CODE BEGIN RTC_MspDeInit 1 */
  73. /* USER CODE END RTC_MspDeInit 1 */
  74. }
  75. }
  76. /* USER CODE BEGIN 1 */
  77. /* USER CODE END 1 */
  78. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/