/** * @brief Configures the current time and date. * @param None * @retval None */ static void RTC_TimeStampConfig(void) { RTC_DateTypeDef sdatestructure; RTC_TimeTypeDef stimestructure; RTC_TamperTypeDef stamperstructure; /*##-1- Configure the Tamper ###############################################*/ /* Configure Tamper registers */ /* RTC Tamper configured as follow: - Pamper = Tamper1 - Pin selection = PC13 - Trigger = Falling Edge - TimeStamp On Tamper Detection = Enable */ stamperstructure.Filter = RTC_TAMPERFILTER_DISABLE; stamperstructure.Tamper = RTC_TAMPER_1; stamperstructure.PinSelection = RTC_TAMPERPIN_PC13; stamperstructure.Trigger = RTC_TAMPERTRIGGER_FALLINGEDGE; stamperstructure.SamplingFrequency = RTC_TAMPERSAMPLINGFREQ_RTCCLK_DIV4096; stamperstructure.PrechargeDuration = RTC_TAMPERPRECHARGEDURATION_1RTCCLK; stamperstructure.TamperPullUp = RTC_TAMPER_PULLUP_DISABLE; stamperstructure.TimeStampOnTamperDetection = RTC_TIMESTAMPONTAMPERDETECTION_ENABLE; HAL_RTCEx_SetTamper(&RtcHandle, &stamperstructure); /*##-2- Configure the Time Stamp peripheral ################################*/ /* RTC TimeStamp flag Generation: TimeStamp Rising Edge on PC13 Pin */ HAL_RTCEx_SetTimeStamp_IT(&RtcHandle, RTC_TIMESTAMPEDGE_RISING, RTC_TIMESTAMPPIN_PC13); /* Clear the TIMESTAMP interrupt pending bit */ __HAL_RTC_TIMESTAMP_CLEAR_FLAG(&RtcHandle,RTC_FLAG_TSF); /*##-3- Configure the Date #################################################*/ /* Set Date: Tuesday February 18th 2014 */ sdatestructure.Year = 0x14; sdatestructure.Month = RTC_MONTH_FEBRUARY; sdatestructure.Date = 0x18; sdatestructure.WeekDay = RTC_WEEKDAY_TUESDAY; if(HAL_RTC_SetDate(&RtcHandle,&sdatestructure,RTC_FORMAT_BCD) != HAL_OK) { /* Initialization Error */ Error_Handler(); } /*##-4- Configure the Time #################################################*/ /* Set Time: 08:10:00 */ stimestructure.Hours = 0x08; stimestructure.Minutes = 0x10; stimestructure.Seconds = 0x00; stimestructure.TimeFormat = RTC_HOURFORMAT12_AM; stimestructure.DayLightSaving = RTC_DAYLIGHTSAVING_NONE; stimestructure.StoreOperation = RTC_STOREOPERATION_RESET; if(HAL_RTC_SetTime(&RtcHandle,&stimestructure,RTC_FORMAT_BCD) != HAL_OK) { /* Initialization Error */ Error_Handler(); } }
/** * @brief Configure the current time and date and activate timestamp. * @param None * @retval None */ static void RTC_TimeStampConfig(void) { RTC_DateTypeDef sdatestructure; RTC_TimeTypeDef stimestructure; /*##-1- Configure the Time Stamp peripheral ################################*/ /* RTC TimeStamp generation: TimeStamp Rising Edge on PC.13 Pin */ HAL_RTCEx_SetTimeStamp_IT(&RtcHandle, RTC_TIMESTAMPEDGE_RISING, RTC_TIMESTAMPPIN_PC13); /*##-2- Configure the Date #################################################*/ /* Set Date: Monday April 14th 2014 */ sdatestructure.Year = 0x14; sdatestructure.Month = RTC_MONTH_APRIL; sdatestructure.Date = 0x14; sdatestructure.WeekDay = RTC_WEEKDAY_MONDAY; if(HAL_RTC_SetDate(&RtcHandle,&sdatestructure, RTC_FORMAT_BCD) != HAL_OK) { /* Initialization Error */ Error_Handler(); } /*##-3- Configure the Time #################################################*/ /* Set Time: 08:10:00 */ stimestructure.Hours = 0x08; stimestructure.Minutes = 0x10; stimestructure.Seconds = 0x00; stimestructure.SubSeconds = 0x00; stimestructure.TimeFormat = RTC_HOURFORMAT12_AM; stimestructure.DayLightSaving = RTC_DAYLIGHTSAVING_NONE ; stimestructure.StoreOperation = RTC_STOREOPERATION_RESET; if(HAL_RTC_SetTime(&RtcHandle,&stimestructure, RTC_FORMAT_BCD) != HAL_OK) { /* Initialization Error */ Error_Handler(); } }
/** * @brief RTC Time stamp configuration function * @param TSpinEdgeSel Select the rising edge or falling edge * @arg RTC_TIMESTAMPEDGE_RISING * @arg RTC_TIMESTAMPEDGE_FALLING * * NOTE Time stamp event generated on the PC13 GPIO pin by apply */ void BSP_RTC_TimeStamp_Init(uint8_t TsPinEdgeSel) { HAL_RTCEx_SetTimeStamp_IT(&hrtc_bsp, TsPinEdgeSel, RTC_TIMESTAMPPIN_PC13); }