static void RtcSetConfig( void ) { RTC_InitTypeDef RTC_InitStructure; RTC_TimeTypeDef RTC_TimeStruct; RTC_DateTypeDef RTC_DateStruct; /* Enable the PWR clock */ RCC_APB1PeriphClockCmd( RCC_APB1Periph_PWR, ENABLE ); /* Allow access to RTC */ PWR_RTCAccessCmd( ENABLE ); /* Reset RTC Domain */ RCC_RTCResetCmd( ENABLE ); RCC_RTCResetCmd( DISABLE ); /* Enable the LSE OSC */ RCC_LSEConfig( RCC_LSE_ON ); /* Wait till LSE is ready */ while( RCC_GetFlagStatus( RCC_FLAG_LSERDY ) == RESET ) {} /* Select the RTC Clock Source */ RCC_RTCCLKConfig( RCC_RTCCLKSource_LSE ); /* Enable the RTC Clock */ RCC_RTCCLKCmd( ENABLE ); RTC_TimeStructInit( &RTC_TimeStruct ); RTC_DateStructInit( &RTC_DateStruct ); RTC_SetDate( RTC_Format_BIN, &RTC_DateStruct ); RTC_SetTime( RTC_Format_BIN, &RTC_TimeStruct ); /* Wait for RTC APB registers synchronisation */ RTC_WaitForSynchro( ); /* Configure the RTC data register and RTC prescaler */ RTC_InitStructure.RTC_AsynchPrediv = 0x01; RTC_InitStructure.RTC_SynchPrediv = 0x01; RTC_InitStructure.RTC_HourFormat = RTC_HourFormat_24; RTC_Init( &RTC_InitStructure ); /* Wait for RTC APB registers synchronisation */ RTC_WaitForSynchro( ); }
void rtcSetTime(struct gtm * t) { RTC_TimeTypeDef RTC_TimeStruct; RTC_DateTypeDef RTC_DateStruct; RTC_TimeStructInit(&RTC_TimeStruct); RTC_DateStructInit(&RTC_DateStruct); RTC_TimeStruct.RTC_Hours = t->tm_hour; RTC_TimeStruct.RTC_Minutes = t->tm_min; RTC_TimeStruct.RTC_Seconds = t->tm_sec; RTC_DateStruct.RTC_Year = t->tm_year - 100; RTC_DateStruct.RTC_Month = t->tm_mon + 1; RTC_DateStruct.RTC_Date = t->tm_mday; RTC_SetTime(RTC_Format_BIN, &RTC_TimeStruct); RTC_SetDate(RTC_Format_BIN, &RTC_DateStruct); }