source: trunk/firmware/Src/rtc.c @ 6

Last change on this file since 6 was 6, checked in by f.jahn, 3 months ago
File size: 3.9 KB
Line 
1/**
2  ******************************************************************************
3  * File Name          : RTC.c
4  * Description        : This file provides code for the configuration
5  *                      of the RTC instances.
6  ******************************************************************************
7  * @attention
8  *
9  * <h2><center>&copy; Copyright (c) 2019 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
20/* Includes ------------------------------------------------------------------*/
21#include "rtc.h"
22
23/* USER CODE BEGIN 0 */
24#define RTC_ASYNCH_PREDIV  0x7F   /* LSE as RTC clock */
25#define RTC_SYNCH_PREDIV   0x00FF /* LSE as RTC clock */
26/* USER CODE END 0 */
27
28RTC_HandleTypeDef hrtc;
29
30/* RTC init function */
31void MX_RTC_Init(void)
32{
33  RTC_TimeTypeDef sTime = {0};
34  RTC_DateTypeDef sDate = {0};
35
36  /** Initialize RTC Only
37  */
38  hrtc.Instance = RTC;
39  hrtc.Init.HourFormat = RTC_HOURFORMAT_24;
40  hrtc.Init.AsynchPrediv = RTC_ASYNCH_PREDIV;
41  hrtc.Init.SynchPrediv = RTC_SYNCH_PREDIV;
42  hrtc.Init.OutPut = RTC_OUTPUT_DISABLE;
43  hrtc.Init.OutPutRemap = RTC_OUTPUT_REMAP_NONE;
44  hrtc.Init.OutPutPolarity = RTC_OUTPUT_POLARITY_HIGH;
45  hrtc.Init.OutPutType = RTC_OUTPUT_TYPE_OPENDRAIN;
46  hrtc.Init.OutPutPullUp = RTC_OUTPUT_PULLUP_NONE;
47  if (HAL_RTC_Init(&hrtc) != HAL_OK)
48  {
49    Error_Handler();
50  }
51
52  /* USER CODE BEGIN Check_RTC_BKUP */
53   
54  /* USER CODE END Check_RTC_BKUP */
55
56  /** Initialize RTC and set the Time and Date
57  */
58  sTime.Hours = 0x02;
59  sTime.Minutes = 0x0;
60  sTime.Seconds = 0x0;
61  sTime.SubSeconds = 0;
62  sTime.DayLightSaving = RTC_DAYLIGHTSAVING_NONE;
63  sTime.StoreOperation = RTC_STOREOPERATION_RESET;
64  if (HAL_RTC_SetTime(&hrtc, &sTime, RTC_FORMAT_BCD) != HAL_OK)
65  {
66    Error_Handler();
67  }
68  sDate.WeekDay = RTC_WEEKDAY_MONDAY;
69  sDate.Month = RTC_MONTH_APRIL;
70  sDate.Date = 0x16;
71  sDate.Year = 0x18;
72
73  if (HAL_RTC_SetDate(&hrtc, &sDate, RTC_FORMAT_BCD) != HAL_OK)
74  {
75    Error_Handler();
76  }
77
78}
79
80void HAL_RTC_MspInit(RTC_HandleTypeDef* rtcHandle)
81{
82
83  if(rtcHandle->Instance==RTC)
84  {
85  /* USER CODE BEGIN RTC_MspInit 0 */
86    /* Enables the PWR Clock and Enables access to the backup domain */
87    /* To change the source clock of the RTC feature (LSE, LSI), You have to:
88       - Enable the power clock using __HAL_RCC_PWR_CLK_ENABLE()
89       - Enable write access using HAL_PWR_EnableBkUpAccess() function before to
90         configure the RTC clock source (to be done once after reset).
91       - Reset the Back up Domain using __HAL_RCC_BACKUPRESET_FORCE() and
92         __HAL_RCC_BACKUPRESET_RELEASE().
93       - Configure the needed RTc clock source */
94      __HAL_RCC_RTCAPB_CLK_ENABLE();
95  /* USER CODE END RTC_MspInit 0 */
96      /* RTC clock enable */
97      __HAL_RCC_RTC_ENABLE();
98  /* USER CODE BEGIN RTC_MspInit 1 */
99//    __HAL_RCC_PWR_CLK_ENABLE();
100//    HAL_PWR_EnableBkUpAccess();
101  /* USER CODE END RTC_MspInit 1 */
102  }
103}
104
105void HAL_RTC_MspDeInit(RTC_HandleTypeDef* rtcHandle)
106{
107
108  if(rtcHandle->Instance==RTC)
109  {
110  /* USER CODE BEGIN RTC_MspDeInit 0 */
111
112  /* USER CODE END RTC_MspDeInit 0 */
113    /* Peripheral clock disable */
114    __HAL_RCC_RTC_DISABLE();
115  /* USER CODE BEGIN RTC_MspDeInit 1 */
116    /* Disables the PWR Clock and Disables access to the backup domain */
117    __HAL_RCC_RTCAPB_CLK_DISABLE();
118  /* USER CODE END RTC_MspDeInit 1 */
119  }
120} 
121
122/* USER CODE BEGIN 1 */
123
124/* USER CODE END 1 */
125
126/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
Note: See TracBrowser for help on using the repository browser.