| /** | |
| ****************************************************************************** | |
| * File Name : RTC.c | |
| * Date : 28/01/2015 07:01:44 | |
| * Description : This file provides code for the configuration | |
| * of the RTC instances. | |
| ****************************************************************************** | |
| * | |
| * COPYRIGHT(c) 2015 STMicroelectronics | |
| * | |
| * Redistribution and use in source and binary forms, with or without modification, | |
| * are permitted provided that the following conditions are met: | |
| * 1. Redistributions of source code must retain the above copyright notice, | |
| * this list of conditions and the following disclaimer. | |
| * 2. Redistributions in binary form must reproduce the above copyright notice, | |
| * this list of conditions and the following disclaimer in the documentation | |
| * and/or other materials provided with the distribution. | |
| * 3. Neither the name of STMicroelectronics nor the names of its contributors | |
| * may be used to endorse or promote products derived from this software | |
| * without specific prior written permission. | |
| * | |
| * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | |
| * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
| * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |
| * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE | |
| * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
| * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | |
| * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | |
| * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | |
| * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
| * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
| * | |
| ****************************************************************************** | |
| */ | |
| /* Includes ------------------------------------------------------------------*/ | |
| /* USER CODE BEGIN 0 */ | |
| /* USER CODE END 0 */ | |
| RTC_HandleTypeDef hrtc; | |
| /* RTC init function */ | |
| void MX_RTC_Init(void) | |
| { | |
| RTC_TimeTypeDef sTime; | |
| RTC_DateTypeDef sDate; | |
| RTC_AlarmTypeDef sAlarm; | |
| /**Initialize RTC and set the Time and Date | |
| */ | |
| hrtc.Instance = RTC; | |
| hrtc.Init.HourFormat = RTC_HOURFORMAT_24; | |
| hrtc.Init.AsynchPrediv = 127; | |
| hrtc.Init.SynchPrediv = 255; | |
| hrtc.Init.OutPut = RTC_OUTPUT_DISABLE; | |
| hrtc.Init.OutPutPolarity = RTC_OUTPUT_POLARITY_HIGH; | |
| hrtc.Init.OutPutType = RTC_OUTPUT_TYPE_OPENDRAIN; | |
| HAL_RTC_Init(&hrtc); | |
| sTime.Hours = 0; | |
| sTime.Minutes = 0; | |
| sTime.Seconds = 0; | |
| sTime.SubSeconds = 0; | |
| sTime.TimeFormat = RTC_HOURFORMAT12_AM; | |
| sTime.DayLightSaving = RTC_DAYLIGHTSAVING_NONE; | |
| sTime.StoreOperation = RTC_STOREOPERATION_RESET; | |
| HAL_RTC_SetTime(&hrtc, &sTime, FORMAT_BCD); | |
| sDate.WeekDay = RTC_WEEKDAY_MONDAY; | |
| sDate.Month = RTC_MONTH_JANUARY; | |
| sDate.Date = 1; | |
| sDate.Year = 0; | |
| HAL_RTC_SetDate(&hrtc, &sDate, FORMAT_BCD); | |
| /**Enable the Alarm A | |
| */ | |
| sAlarm.AlarmTime.Hours = 0; | |
| sAlarm.AlarmTime.Minutes = 0; | |
| sAlarm.AlarmTime.Seconds = 0; | |
| sAlarm.AlarmTime.SubSeconds = 0; | |
| sAlarm.AlarmTime.TimeFormat = RTC_HOURFORMAT12_AM; | |
| sAlarm.AlarmTime.DayLightSaving = RTC_DAYLIGHTSAVING_NONE; | |
| sAlarm.AlarmTime.StoreOperation = RTC_STOREOPERATION_RESET; | |
| sAlarm.AlarmMask = RTC_ALARMMASK_NONE; | |
| sAlarm.AlarmSubSecondMask = RTC_ALARMSUBSECONDMASK_ALL; | |
| sAlarm.AlarmDateWeekDaySel = RTC_ALARMDATEWEEKDAYSEL_DATE; | |
| sAlarm.AlarmDateWeekDay = 1; | |
| sAlarm.Alarm = RTC_ALARM_A; | |
| HAL_RTC_SetAlarm_IT(&hrtc, &sAlarm, FORMAT_BCD); | |
| /**Enable the WakeUp | |
| */ | |
| HAL_RTCEx_SetWakeUpTimer_IT(&hrtc, 0, RTC_WAKEUPCLOCK_RTCCLK_DIV16); | |
| } | |
| void HAL_RTC_MspInit(RTC_HandleTypeDef* hrtc) | |
| { | |
| if(hrtc->Instance==RTC) | |
| { | |
| /* USER CODE BEGIN RTC_MspInit 0 */ | |
| /* USER CODE END RTC_MspInit 0 */ | |
| /* Peripheral clock enable */ | |
| __HAL_RCC_RTC_ENABLE(); | |
| /* Peripheral interrupt init*/ | |
| HAL_NVIC_SetPriority(RTC_IRQn, 0, 0); | |
| HAL_NVIC_EnableIRQ(RTC_IRQn); | |
| /* USER CODE BEGIN RTC_MspInit 1 */ | |
| /* USER CODE END RTC_MspInit 1 */ | |
| } | |
| } | |
| void HAL_RTC_MspDeInit(RTC_HandleTypeDef* hrtc) | |
| { | |
| if(hrtc->Instance==RTC) | |
| { | |
| /* USER CODE BEGIN RTC_MspDeInit 0 */ | |
| /* USER CODE END RTC_MspDeInit 0 */ | |
| /* Peripheral clock disable */ | |
| __HAL_RCC_RTC_DISABLE(); | |
| /* Peripheral interrupt Deinit*/ | |
| HAL_NVIC_DisableIRQ(RTC_IRQn); | |
| /* USER CODE BEGIN RTC_MspDeInit 1 */ | |
| /* USER CODE END RTC_MspDeInit 1 */ | |
| } | |
| } | |
| /* USER CODE BEGIN 1 */ | |
| /* USER CODE END 1 */ | |
| /** | |
| * @} | |
| */ | |
| /** | |
| * @} | |
| */ | |
| /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ | |