comparison Small_CPU/Src/rtc.c @ 38:5f11787b4f42

include in ostc4 repository
author heinrichsweikamp
date Sat, 28 Apr 2018 11:52:34 +0200
parents
children f0069f002c55
comparison
equal deleted inserted replaced
37:ccc45c0e1ea2 38:5f11787b4f42
1 /**
2 ******************************************************************************
3 * @file rtc.c
4 * @author heinrichs weikamp gmbh
5 * @version V0.0.1
6 * @date 10-Oct-2014
7 * @brief Source code for rtc control
8 *
9 @verbatim
10 ==============================================================================
11 ##### How to use #####
12 ==============================================================================
13 @endverbatim
14 ******************************************************************************
15 * @attention
16 *
17 * <h2><center>&copy; COPYRIGHT(c) 2015 heinrichs weikamp</center></h2>
18 *
19 ******************************************************************************
20 */
21 /* Includes ------------------------------------------------------------------*/
22 #include "rtc.h"
23 #include "stm32f4xx_hal.h"
24 #include "stm32f4xx_hal_conf.h"
25 #include "baseCPU2.h"
26
27 RTC_HandleTypeDef RTCHandle;
28
29 static void RTC_Error_Handler(void);
30
31
32 void RTC_SetTime(RTC_TimeTypeDef stimestructure)
33 {
34
35 stimestructure.SubSeconds = 0;
36 stimestructure.TimeFormat = RTC_HOURFORMAT12_AM;
37 stimestructure.DayLightSaving = RTC_DAYLIGHTSAVING_NONE ;
38 stimestructure.StoreOperation = RTC_STOREOPERATION_RESET;
39
40 if(HAL_RTC_SetTime(&RTCHandle, &stimestructure, FORMAT_BIN) != HAL_OK)
41 {
42 RTC_Error_Handler();
43 }
44 }
45
46
47 void RTC_SetDate(RTC_DateTypeDef sdatestructure)
48 {
49 if(HAL_RTC_SetDate(&RTCHandle, &sdatestructure, FORMAT_BIN) != HAL_OK)
50 {
51 RTC_Error_Handler();
52 }
53 }
54
55
56 /*
57 static void RTC_CalendarConfig(void)
58 {
59 RTC_DateTypeDef sdatestructure;
60 RTC_TimeTypeDef stimestructure;
61
62 //##-1- Configure the Date #################################################
63 // Set Date: Monday April 14th 2014
64 sdatestructure.Year = 0;
65 sdatestructure.Month = RTC_MONTH_JANUARY;
66 sdatestructure.Date = 1;
67 sdatestructure.WeekDay = RTC_WEEKDAY_MONDAY;
68
69 if(HAL_RTC_SetDate(&RTCHandle,&sdatestructure,FORMAT_BCD) != HAL_OK)
70 {
71 RTC_Error_Handler();
72 }
73
74 //##-2- Configure the Time #################################################
75 // Set Time: 02:00:00
76 stimestructure.Hours = 0;
77 stimestructure.Minutes = 0;
78 stimestructure.Seconds = 0;
79 stimestructure.DayLightSaving = RTC_DAYLIGHTSAVING_NONE ;
80 stimestructure.StoreOperation = RTC_STOREOPERATION_RESET;
81
82 if(HAL_RTC_SetTime(&RTCHandle,&stimestructure,FORMAT_BCD) != HAL_OK)
83 {
84 RTC_Error_Handler();
85 }
86
87 //##-3- Writes a data in a RTC Backup data Register0 #######################
88 // HAL_RTCEx_BKUPWrite(&RTCHandle,RTC_BKP_DR0,0x32F2);
89 }
90 */
91
92
93 /* ##-1- Configure the RTC peripheral #######################################
94 Configure RTC prescaler and RTC data registers
95 RTC configured as follow:
96 - Hour Format = Format 24
97 - Asynch Prediv = Value according to source clock
98 - Synch Prediv = Value according to source clock
99 - OutPut = Output Disable
100 - OutPutPolarity = High Polarity
101 - OutPutType = Open Drain
102 */
103
104
105 void MX_RTC_init(void)
106 {
107
108 RTC_TimeTypeDef sTime;
109 RTC_DateTypeDef sDate;
110 // RTC_AlarmTypeDef sAlarm;
111
112 /**Initialize RTC and set the Time and Date
113 */
114 RTCHandle.Instance = RTC;
115 RTCHandle.Init.HourFormat = RTC_HOURFORMAT_24;
116 RTCHandle.Init.AsynchPrediv = 127;
117 RTCHandle.Init.SynchPrediv = 255;
118 RTCHandle.Init.OutPut = RTC_OUTPUT_DISABLE;
119 RTCHandle.Init.OutPutPolarity = RTC_OUTPUT_POLARITY_HIGH;
120 RTCHandle.Init.OutPutType = RTC_OUTPUT_TYPE_OPENDRAIN;
121 HAL_RTC_Init(&RTCHandle);
122
123 sTime.Hours = 11;
124 sTime.Minutes = 0;
125 sTime.Seconds = 0;
126 sTime.SubSeconds = 0;
127 sTime.TimeFormat = RTC_HOURFORMAT12_AM;
128 sTime.DayLightSaving = RTC_DAYLIGHTSAVING_NONE;
129 sTime.StoreOperation = RTC_STOREOPERATION_RESET;
130 HAL_RTC_SetTime(&RTCHandle, &sTime, FORMAT_BCD);
131
132 sDate.WeekDay = RTC_WEEKDAY_SUNDAY;
133 sDate.Month = RTC_MONTH_FEBRUARY;
134 sDate.Date = 15;
135 sDate.Year = 17;
136 HAL_RTC_SetDate(&RTCHandle, &sDate, FORMAT_BCD);
137
138
139 /*
140 RTCHandle.Instance = RTC;
141 RTCHandle.Init.HourFormat = RTC_HOURFORMAT_24;
142 RTCHandle.Init.AsynchPrediv = RTC_ASYNCH_PREDIV;
143 RTCHandle.Init.SynchPrediv = RTC_SYNCH_PREDIV;
144 RTCHandle.Init.OutPut = RTC_OUTPUT_DISABLE;
145 RTCHandle.Init.OutPutPolarity = RTC_OUTPUT_POLARITY_HIGH;
146 RTCHandle.Init.OutPutType = RTC_OUTPUT_TYPE_OPENDRAIN;
147
148 HAL_RTC_Init(&RTCHandle);
149 */
150 }
151
152
153 void RTC_StopMode_2seconds(void)
154 {
155 /* Enable Power Control clock */
156 __HAL_RCC_PWR_CLK_ENABLE();
157
158 /* Disable Wake-up timer */
159 HAL_RTCEx_DeactivateWakeUpTimer(&RTCHandle);
160
161 /* Enable Wake-up timer */
162 HAL_RTCEx_SetWakeUpTimer_IT(&RTCHandle, (0x1000-1), RTC_WAKEUPCLOCK_RTCCLK_DIV16);
163
164 /* FLASH Deep Power Down Mode enabled */
165 HAL_PWREx_EnableFlashPowerDown();
166
167 /*## Enter Stop Mode #######################################################*/
168 HAL_PWR_EnterSTOPMode(PWR_LOWPOWERREGULATOR_ON, PWR_STOPENTRY_WFI);
169
170 /* Configures system clock after wake-up from STOP: enable HSI, PLL and select
171 PLL as system clock source (HSI and PLL are disabled in STOP mode) */
172 SYSCLKConfig_STOP();
173
174 HAL_RTCEx_DeactivateWakeUpTimer(&RTCHandle);
175 }
176
177
178 void RTC_Stop_11ms(void)
179 {
180 /* Disable Wake-up timer */
181 HAL_RTCEx_DeactivateWakeUpTimer(&RTCHandle);
182
183 /* Enable Wake-up timer */
184 HAL_RTCEx_SetWakeUpTimer_IT(&RTCHandle, (0x18-1), RTC_WAKEUPCLOCK_RTCCLK_DIV16);
185
186 /* FLASH Deep Power Down Mode enabled */
187 HAL_PWREx_DisableFlashPowerDown();
188
189 /*## Enter Stop Mode #######################################################*/
190 HAL_PWR_EnterSTOPMode(PWR_MAINREGULATOR_ON, PWR_STOPENTRY_WFI);
191
192 /* Configures system clock after wake-up from STOP: enable HSI, PLL and select
193 PLL as system clock source (HSI and PLL are disabled in STOP mode) */
194 SYSCLKConfig_STOP();
195
196 HAL_RTCEx_DeactivateWakeUpTimer(&RTCHandle);
197 }
198
199
200 static void RTC_Error_Handler(void)
201 {
202 while(1);
203 }
204
205
206 /************************ (C) COPYRIGHT heinrichs weikamp *****END OF FILE****/