Пример #1
1
/**
  * @brief  Main program
  * @param  None
  * @retval None
  */
int main(void)
{
  uint32_t index = 0;
  RTC_TamperTypeDef  stamperstructure;
  
  /* STM32F4xx HAL library initialization:
       - Configure the Flash prefetch
       - Systick timer is configured by default as source of time base, but user 
         can eventually implement his proper time base source (a general purpose 
         timer for example or other time source), keeping in mind that Time base 
         duration should be kept 1ms since PPP_TIMEOUT_VALUEs are defined and 
         handled in milliseconds basis.
       - Set NVIC Group Priority to 4
       - Low Level Initialization
     */
  HAL_Init();


  /* Configure the system clock to 180 MHz */
  SystemClock_Config();

  /* Wait until MFX is ready after reset */
  HAL_Delay(100);
  
  /* Since MFX is used, LED init is done after clock config */
  /* Configure LED1, LED2, LED3 and LED4 */
  BSP_LED_Init(LED1);
  BSP_LED_Init(LED2);
  BSP_LED_Init(LED3);
  BSP_LED_Init(LED4);
  
  /* Configure Tamper push-button button */
  BSP_PB_Init(BUTTON_TAMPER, BUTTON_MODE_GPIO);
  
  /*##-1- Configure the RTC peripheral #######################################*/
  /* Configure RTC prescaler and RTC data registers */
  /* RTC configured as follows:
      - Hour Format    = Format 24
      - Asynch Prediv  = Value according to source clock
      - Synch Prediv   = Value according to source clock
      - OutPut         = Output Disable
      - OutPutPolarity = High Polarity
      - OutPutType     = Open Drain */
  RtcHandle.Init.HourFormat     = RTC_HOURFORMAT_24;
  RtcHandle.Init.AsynchPrediv   = RTC_ASYNCH_PREDIV;
  RtcHandle.Init.SynchPrediv    = RTC_SYNCH_PREDIV;
  RtcHandle.Init.OutPut         = RTC_OUTPUT_DISABLE;
  RtcHandle.Init.OutPutPolarity = RTC_OUTPUT_POLARITY_HIGH;
  RtcHandle.Init.OutPutType     = RTC_OUTPUT_TYPE_OPENDRAIN;
  RtcHandle.Instance            = RTC;
  
  if (HAL_RTC_Init(&RtcHandle) != HAL_OK)
  {
    /* Initialization Error */
    Error_Handler();
  }

  /*##-2- Configure RTC Tamper ###############################################*/
  stamperstructure.Tamper                       = RTC_TAMPER_1;
  stamperstructure.PinSelection                 = RTC_TAMPERPIN_PC13;
  stamperstructure.Trigger                      = RTC_TAMPERTRIGGER_FALLINGEDGE;
  stamperstructure.Filter                       = RTC_TAMPERFILTER_DISABLE;
  stamperstructure.SamplingFrequency            = RTC_TAMPERSAMPLINGFREQ_RTCCLK_DIV32768;
  stamperstructure.PrechargeDuration            = RTC_TAMPERPRECHARGEDURATION_1RTCCLK;
  stamperstructure.TamperPullUp                 = RTC_TAMPER_PULLUP_ENABLE;
  stamperstructure.TimeStampOnTamperDetection   = RTC_TIMESTAMPONTAMPERDETECTION_DISABLE;
  
  if (HAL_RTCEx_SetTamper_IT(&RtcHandle, &stamperstructure) != HAL_OK)
  {
    /* Initialization Error */
    Error_Handler();
  }

  /* Clear the Tamper interrupt pending bit */
  __HAL_RTC_TAMPER_CLEAR_FLAG(&RtcHandle,RTC_FLAG_TAMP1F);

  /*##-3- Write Data on the Back Up registers ################################*/
  for (index = 0; index < BACKUP_COUNT; index++)
  {
    HAL_RTCEx_BKUPWrite(&RtcHandle, aBKPDataReg[index], 0xDF59 + (index * 0x5A));
  }

  /*##-4- Check Data is stored on the Back Up registers ######################*/
  for (index = 0; index < BACKUP_COUNT; index++)
  {
    if (HAL_RTCEx_BKUPRead(&RtcHandle, aBKPDataReg[index]) != (0xDF59 + (index * 0x5A)))
    {
      Error_Handler();
    }
  }

  /* Turn LED2 on */
  BSP_LED_On(LED2);

  /*##-5- Wait for the tamper button is pressed ##############################*/
  while (TamperStatus != SET);

  /*##-6- Deactivate the tamper                 ##############################*/
  HAL_RTCEx_DeactivateTamper(&RtcHandle, RTC_TAMPER_1);
    
  /*##-7- Check Data is cleared on the Back Up registers #####################*/
  for (index = 0; index < BACKUP_COUNT; index++)
  {
    if (HAL_RTCEx_BKUPRead(&RtcHandle, aBKPDataReg[index]) != 0x00)
    {
      Error_Handler();
    }
  }

  /* Infinite loop */
  while (1)
  {
    /* Turn LED4 on */
    BSP_LED_Toggle(LED4);

    /* Delay */
    HAL_Delay(100);
  }
}
Пример #2
0
//-----------------------------------------------------------
void rtc_init()
{
  HAL_RTCEx_DeactivateWakeUpTimer(&hrtc);
	HAL_RTCEx_BKUPWrite(&hrtc, RTC_BKP_DR2, 0xaaaa);
	osMutexDef(rtc_mutex); 
	rtc_mutex = osMutexCreate(osMutex(rtc_mutex));
}
Пример #3
0
Файл: rtc.c Проект: theapi/solar
/* RTC init function */
void MX_RTC_Init(void)
{
  RTC_TimeTypeDef sTime;
  RTC_DateTypeDef sDate;

    /**Initialize RTC Only 
    */
  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.OutPutRemap = RTC_OUTPUT_REMAP_NONE;
  hrtc.Init.OutPutPolarity = RTC_OUTPUT_POLARITY_HIGH;
  hrtc.Init.OutPutType = RTC_OUTPUT_TYPE_OPENDRAIN;
  if (HAL_RTC_Init(&hrtc) != HAL_OK)
  {
    _Error_Handler(__FILE__, __LINE__);
  }

    /**Initialize RTC and set the Time and Date 
    */
  if(HAL_RTCEx_BKUPRead(&hrtc, RTC_BKP_DR0) != 0x32F2){
  sTime.Hours = 0x0;
  sTime.Minutes = 0x0;
  sTime.Seconds = 0x0;
  sTime.DayLightSaving = RTC_DAYLIGHTSAVING_NONE;
  sTime.StoreOperation = RTC_STOREOPERATION_RESET;
  if (HAL_RTC_SetTime(&hrtc, &sTime, RTC_FORMAT_BCD) != HAL_OK)
  {
    _Error_Handler(__FILE__, __LINE__);
  }

  sDate.WeekDay = RTC_WEEKDAY_MONDAY;
  sDate.Month = RTC_MONTH_JANUARY;
  sDate.Date = 0x1;
  sDate.Year = 0x0;

  if (HAL_RTC_SetDate(&hrtc, &sDate, RTC_FORMAT_BCD) != HAL_OK)
  {
    _Error_Handler(__FILE__, __LINE__);
  }

    HAL_RTCEx_BKUPWrite(&hrtc,RTC_BKP_DR0,0x32F2);
  }
    /**Enable the WakeUp 
    */
  if (HAL_RTCEx_SetWakeUpTimer_IT(&hrtc, 5, RTC_WAKEUPCLOCK_CK_SPRE_16BITS) != HAL_OK)
  {
    _Error_Handler(__FILE__, __LINE__);
  }

}
Пример #4
0
static uint8_t rtc_check()
{
	uint8_t hour,min;
	RTC_AlarmTypeDef sAlarm;
	RTC_DateTypeDef sdatestructureget;
  RTC_TimeTypeDef stimestructureget;
	if (HAL_RTCEx_BKUPRead(&hrtc, RTC_BKP_DR1) != 0x32F2)
	{	
		HAL_RTCEx_BKUPWrite(&hrtc, RTC_BKP_DR1, 0x32F2);
		return 0;
	}
	else
	{
		//read time
		HAL_RTC_GetTime(&hrtc, &stimestructureget, RTC_FORMAT_BIN);		
		HAL_RTC_GetDate(&hrtc, &sdatestructureget, RTC_FORMAT_BIN);
		//set alarm
		    /**Enable the Alarm A 
			*/
			hour=stimestructureget.Hours;
			min=stimestructureget.Minutes+1;
			if(min>59)
			{	
				min-=60;
				if(hour==23)
					hour=0;
				else
					hour++;
			}

		sAlarm.AlarmTime.Hours = hour;
		sAlarm.AlarmTime.Minutes = min;
		sAlarm.AlarmTime.Seconds = 1;
		sAlarm.AlarmTime.SubSeconds = 0;
		sAlarm.AlarmTime.DayLightSaving = RTC_DAYLIGHTSAVING_NONE;
		sAlarm.AlarmTime.StoreOperation = RTC_STOREOPERATION_RESET;
		sAlarm.AlarmMask = RTC_ALARMMASK_DATEWEEKDAY;
		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_BIN);

		return 1;
	}

}
/**
 * @brief  Configure the current time and date.
 * @param  None
 * @retval None
 */
static void RTC_CalendarConfig(void)
{
    RTC_DateTypeDef sdatestructure;
    RTC_TimeTypeDef stimestructure;

    /*##-1- Configure the Date #################################################*/
    /* Set Date: Friday January 1st 2016 */
    sdatestructure.Year = 0x16;
    sdatestructure.Month = RTC_MONTH_JANUARY;
    sdatestructure.Date = 0x01;
    sdatestructure.WeekDay = RTC_WEEKDAY_FRIDAY;

    if(HAL_RTC_SetDate(&RtcHandle,&sdatestructure,RTC_FORMAT_BCD) != HAL_OK)
    {
        /* Initialization Error */
        //Error_Handler();
        while(1)
        {}
    }

    /*##-2- Configure the Time #################################################*/
    /* Set Time: 00:00:00 */
    stimestructure.Hours = 0x00;
    stimestructure.Minutes = 0x00;
    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();
        while(1)
        {}
    }

    /*##-3- Writes a data in a RTC Backup data Register1 #######################*/
    HAL_RTCEx_BKUPWrite(&RtcHandle, RTC_BKP_DR1, 0x32F2);
}
Пример #6
0
void RTC_CalendarConfig(time_t unixtime)
{
	DateTime date;
	RTC_DateTypeDef sdatestructure;
	RTC_TimeTypeDef stimestructure;

	convertUnixTimeToDate(unixtime, &date);

	/*##-1- Configure the Date #################################################*/
	/* Set Date: Tuesday February 18th 2014 */
	sdatestructure.Year = (uint8_t)(date.year - 2000);
	sdatestructure.Month = date.month;
	sdatestructure.Date = date.day;
	sdatestructure.WeekDay = date.dayOfWeek;

	if(HAL_RTC_SetDate(&RtcHandle,&sdatestructure,FORMAT_BIN) != HAL_OK)
	{
		/* Initialization Error */
		Error_Handler();
	}

	/*##-2- Configure the Time #################################################*/
	/* Set Time: 02:00:00 */
	stimestructure.Hours = date.hours;
	stimestructure.Minutes = date.minutes;
	stimestructure.Seconds = date.seconds;
	stimestructure.TimeFormat = RTC_HOURFORMAT12_AM;
	stimestructure.DayLightSaving = RTC_DAYLIGHTSAVING_NONE ;
	stimestructure.StoreOperation = RTC_STOREOPERATION_RESET;

	if (HAL_RTC_SetTime(&RtcHandle, &stimestructure, FORMAT_BIN) != HAL_OK)
	{
		/* Initialization Error */
		Error_Handler();
	}

	/*##-3- Writes a data in a RTC Backup data Register0 #######################*/
	HAL_RTCEx_BKUPWrite(&RtcHandle, RTC_BKP_DR0, 0x32F2);
}
void mo_Set_UnixTime_hal(time_t unix_time)
{
    struct tm *tmTemp = gmtime( &unix_time );//localtime( &unix_time);

    RTC_DateTypeDef sdatestructure;
    RTC_TimeTypeDef stimestructure;

    /*##-1- Configure the Date #################################################*/
    sdatestructure.Year  = tmTemp->tm_year + 1904;
    sdatestructure.Month = tmTemp->tm_mon + 1;
    sdatestructure.Date  = tmTemp->tm_mday;

    if(HAL_RTC_SetDate(&RtcHandle,&sdatestructure,RTC_FORMAT_BCD) != HAL_OK)
    {
        /* Initialization Error */
        //Error_Handler();
        while(1)
        {}
    }

    /*##-2- Configure the Time #################################################*/
    stimestructure.Hours   = tmTemp->tm_hour;
    stimestructure.Minutes = tmTemp->tm_min;
    stimestructure.Seconds = tmTemp->tm_sec;
    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();
        while(1)
        {}
    }

    /*##-3- Writes a data in a RTC Backup data Register1 #######################*/
    HAL_RTCEx_BKUPWrite(&RtcHandle, RTC_BKP_DR1, 0x32F2);
}
Пример #8
0
/**
  * @brief  Configure the current time and date.
  * @param  None
  * @retval None
  */
static void RTC_CalendarConfig(void)
{
  RTC_DateTypeDef sdatestructure;
  RTC_TimeTypeDef stimestructure;

  /*##-1- 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,FORMAT_BCD) != HAL_OK)
  {
    /* Initialization Error */
    Error_Handler();
  }

  /*##-2- Configure the Time #################################################*/
  /* Set Time: 02:00:00 */
  stimestructure.Hours = 0x02;
  stimestructure.Minutes = 0x00;
  stimestructure.Seconds = 0x00;
  stimestructure.TimeFormat = RTC_HOURFORMAT12_AM;
  stimestructure.DayLightSaving = RTC_DAYLIGHTSAVING_NONE ;
  stimestructure.StoreOperation = RTC_STOREOPERATION_RESET;

  if (HAL_RTC_SetTime(&RtcHandle, &stimestructure, FORMAT_BCD) != HAL_OK)
  {
    /* Initialization Error */
    Error_Handler();
  }

  /*##-3- Writes a data in a RTC Backup data Register0 #######################*/
  HAL_RTCEx_BKUPWrite(&RtcHandle, RTC_BKP_DR0, 0x32F2);
}
Пример #9
0
/**
  * @brief RTC MSP De-Initialization
  *        This function frees the hardware resources used in this application:
  *          - Disable the Peripheral's clock
  * @param hrtc: RTC handle pointer
  * @retval None
  */
void BACKUP_SaveParameter(uint32_t address, uint32_t data)
{
    HAL_RTCEx_BKUPWrite(&RtcHandle,address,data);
}
Пример #10
0
uint32_t TM_RTC_Init(TM_RTC_ClockSource_t source) {
	uint32_t status;
	TM_RTC_t datatime;
	
	/* Set instance */
	hRTC.Instance = RTC;
	hRTC.Init.AsynchPrediv = RTC_ASYNC_PREDIV;
	hRTC.Init.SynchPrediv = RTC_SYNC_PREDIV;
	hRTC.Init.HourFormat = RTC_HOURFORMAT_24;
	hRTC.Init.OutPut = RTC_OUTPUT_DISABLE;
	hRTC.Init.OutPutType = RTC_OUTPUT_TYPE_PUSHPULL;
	hRTC.Init.OutPutPolarity = RTC_OUTPUT_POLARITY_HIGH;
	
	/* Enable PWR peripheral clock */
	__HAL_RCC_PWR_CLK_ENABLE();

	/* Allow access to BKP Domain */
	HAL_PWR_EnableBkUpAccess();
	
	/* Get RTC status */
	status = HAL_RTCEx_BKUPRead(&hRTC, RTC_STATUS_REG);
	
	/* Check if RTC already initialized */
	if (status == RTC_STATUS_TIME_OK) {
		/* Start internal clock if we choose internal clock */
		if (source == TM_RTC_ClockSource_Internal) {
			TM_RTC_Config(TM_RTC_ClockSource_Internal);
		}
		
		/* Wait for RTC APB registers synchronisation (needed after start-up from Reset) */
		HAL_RTC_WaitForSynchro(&hRTC);
		
		/* Get date and time */
		TM_RTC_GetDateTime(&datatime, TM_RTC_Format_BIN);
		
		/* Clear reset flags */
		__HAL_RCC_CLEAR_RESET_FLAGS();
		
		/* Return OK */
		return 1;
	} else {
		/* Start RTC clock */
		TM_RTC_Config(source);
		
		/* Set date */
		RTC_DateStruct.Year = 0;
		RTC_DateStruct.Month = 1;
		RTC_DateStruct.Date = 1;
		RTC_DateStruct.WeekDay = RTC_WEEKDAY_TUESDAY;

		/* Set date */
		HAL_RTC_SetDate(&hRTC, &RTC_DateStruct, RTC_FORMAT_BIN);

		/* Set time */
		RTC_TimeStruct.Hours = 0x00;
		RTC_TimeStruct.Minutes = 0x00;
		RTC_TimeStruct.Seconds = 0x00;
		RTC_TimeStruct.TimeFormat = RTC_HOURFORMAT_24;
		RTC_TimeStruct.DayLightSaving = RTC_DAYLIGHTSAVING_NONE;
		RTC_TimeStruct.StoreOperation = RTC_STOREOPERATION_RESET;

		/* Set time */
		HAL_RTC_SetTime(&hRTC, &RTC_TimeStruct, RTC_FORMAT_BCD);
		
		/* Init RTC */
		HAL_RTC_Init(&hRTC);

		/* Save data to backup regiser */
		HAL_RTCEx_BKUPWrite(&hRTC, RTC_STATUS_REG, RTC_STATUS_TIME_OK); 
		
		/* RTC was initialized now */
		return 0;
	}
}
Пример #11
0
/**
  * @brief  Main program
  * @param  None
  * @retval None
  */
int main(void)
{
  uint32_t index = 0;
  RTC_TamperTypeDef  stamperstructure;
  
  /* STM32F103xG HAL library initialization:
       - Configure the Flash prefetch
       - Systick timer is configured by default as source of time base, but user 
         can eventually implement his proper time base source (a general purpose 
         timer for example or other time source), keeping in mind that Time base 
         duration should be kept 1ms since PPP_TIMEOUT_VALUEs are defined and 
         handled in milliseconds basis.
       - Set NVIC Group Priority to 4
       - Low Level Initialization
     */
  HAL_Init();

  /* Configure the system clock to 72 MHz */
  SystemClock_Config();

  /* Configure LED1, LED2, LED3 and LED4 */
  BSP_LED_Init(LED1);
  BSP_LED_Init(LED2);
  BSP_LED_Init(LED3);
  BSP_LED_Init(LED4);

  /* Configure Key push-button button */
  BSP_PB_Init(BUTTON_KEY, BUTTON_MODE_GPIO);
  
  /*##-1- Configure the RTC peripheral #######################################*/
  /* Configure RTC prescaler and RTC data registers */
  /* RTC configured as follow:
      - Asynch Prediv  = Calculated automatically by HAL */
  RtcHandle.Instance            = RTC;
  RtcHandle.Init.AsynchPrediv   = RTC_AUTO_1_SECOND;
  
  if (HAL_RTC_Init(&RtcHandle) != HAL_OK)
  {
    /* Initialization Error */
    Error_Handler();
  }

  /*##-2- Configure RTC Tamper ###############################################*/
  stamperstructure.Tamper                       = RTC_TAMPER_1;
  stamperstructure.Trigger                      = RTC_TAMPERTRIGGER_LOWLEVEL;

  if (HAL_RTCEx_SetTamper_IT(&RtcHandle, &stamperstructure) != HAL_OK)
  {
    /* Initialization Error */
    Error_Handler();
  }

  /* Clear the Tamper interrupt pending bit */
  __HAL_RTC_TAMPER_CLEAR_FLAG(&RtcHandle,RTC_FLAG_TAMP1F);

  /*##-3- Write Data on the Back Up registers ################################*/
  for (index = 0; index < BACKUP_COUNT; index++)
  {
    HAL_RTCEx_BKUPWrite(&RtcHandle, aBKPDataReg[index], 0xDF59 + (index * 0x5A));
  }

  /*##-4- Check Data is stored on the Back Up registers ######################*/
  for (index = 0; index < BACKUP_COUNT; index++)
  {
    if (HAL_RTCEx_BKUPRead(&RtcHandle, aBKPDataReg[index]) != (0xDF59 + (index * 0x5A)))
    {
      Error_Handler();
    }
  }

  /* Turn LED2 on */
  BSP_LED_On(LED2);

  /*##-5- Wait for the tamper button is pressed ##############################*/
  while (TamperStatus != SET);
  

  /*##-6- Deactivate the tamper                 ##############################*/
  HAL_RTCEx_DeactivateTamper(&RtcHandle, RTC_TAMPER_1);
    
  /*##-7- Check Data is cleared on the Back Up registers #####################*/
  for (index = 0; index < BACKUP_COUNT; index++)
  {
    if (HAL_RTCEx_BKUPRead(&RtcHandle, aBKPDataReg[index]) != 0x00)
    {
      Error_Handler();
    }
  }

  /* Infinite loop */
  while (1)
  {
    /* Turn LED4 on */
    BSP_LED_Toggle(LED4);

    /* Delay */
    HAL_Delay(100);
  }
}
Пример #12
0
void RTC_Init(void)
{

  RTC_DateTypeDef DateToUpdate;
	
    HAL_PWR_EnableBkUpAccess();
    /* Enable BKP CLK enable for backup registers */
    __HAL_RCC_BKP_CLK_ENABLE();
    /* Peripheral clock enable */
    __HAL_RCC_RTC_ENABLE();
    /* Peripheral interrupt init */
    HAL_NVIC_SetPriority(RTC_IRQn, 0, 0);
    HAL_NVIC_EnableIRQ(RTC_IRQn);
    HAL_NVIC_SetPriority(RTC_Alarm_IRQn, 0, 0);
    HAL_NVIC_EnableIRQ(RTC_Alarm_IRQn);	
	
    /**Initialize RTC and set the Time and Date 
    */
		hrtc.Instance = RTC;
		hrtc.Init.AsynchPrediv = RTC_AUTO_1_SECOND;
		hrtc.Init.OutPut = RTC_OUTPUTSOURCE_NONE;
		HAL_RTC_Init(&hrtc);

	if (HAL_RTCEx_BKUPRead(&hrtc, 1) != RTC_IS_SET)
		{// check RTC is init or no
			HAL_RTC_GetDate(&hrtc, &DateToUpdate, RTC_FORMAT_BCD);
			
			if (DateToUpdate.Year == 0x0)
			{
					sTime.Hours = 0x20;
					sTime.Minutes = 0x10;
					sTime.Seconds = 0;

					//HAL_RTC_SetTime(&hrtc, &sTime, RTC_FORMAT_BCD);


					DateToUpdate.WeekDay = RTC_WEEKDAY_THURSDAY;
					DateToUpdate.Month = RTC_MONTH_AUGUST;
					DateToUpdate.Date = 0x11;
					DateToUpdate.Year = 0x16;
					
					//HAL_RTC_SetDate(&hrtc, &DateToUpdate, RTC_FORMAT_BCD);
				
//directly write to counter						
//		if(something == 1)
//		{
//			something = 0;
//			while ((hrtc.Instance->CRL | RTC_CRL_RTOFF) == 0);
//			hrtc.Instance->CRL |= RTC_CRL_CNF;
//			hrtc.Instance->CNTL = 0xD63C;
//			hrtc.Instance->CNTH = 0x57DF;
//			hrtc.Instance->CRL &= ~RTC_CRL_CNF;
//		}


			}
			HAL_RTCEx_BKUPWrite(&hrtc, 1, RTC_IS_SET);
		}
		
		HAL_RTCEx_SetSecond_IT(&hrtc);
	

}
Пример #13
0
/**
  * @brief  Main program
  * @param  None
  * @retval None
  */
int main(void)
{ 
  uint32_t index = 0;
  
  /* STM32F4xx HAL library initialization:
       - Configure the Flash prefetch, instruction and Data caches
       - Configure the Systick to generate an interrupt each 1 msec
       - Set NVIC Group Priority to 4
       - Global MSP (MCU Support Package) initialization
     */
  HAL_Init();
  
  /* Configure LED1, LED2, LED3 and LED4 */
  BSP_LED_Init(LED1);
  BSP_LED_Init(LED2);
  BSP_LED_Init(LED3);
  BSP_LED_Init(LED4);

  /* Configure the system clock to 168 MHz */
  SystemClock_Config();

  RtcHandle.Instance = RTC;
  
  /*##-1- Configure the RTC peripheral #######################################*/
  /* Configure RTC prescaler and RTC data registers */
  /* RTC configured as follow:
  - Hour Format    = Format 24
  - Asynch Prediv  = Value according to source clock
  - Synch Prediv   = Value according to source clock
  - OutPut         = Output Disable
  - OutPutPolarity = High Polarity
  - OutPutType     = Open Drain */ 
  RtcHandle.Init.HourFormat = RTC_HOURFORMAT_24;
  RtcHandle.Init.AsynchPrediv = RTC_ASYNCH_PREDIV;
  RtcHandle.Init.SynchPrediv = RTC_SYNCH_PREDIV;
  RtcHandle.Init.OutPut = RTC_OUTPUT_DISABLE;
  RtcHandle.Init.OutPutPolarity = RTC_OUTPUT_POLARITY_HIGH;
  RtcHandle.Init.OutPutType = RTC_OUTPUT_TYPE_OPENDRAIN;
  
  if(HAL_RTC_Init(&RtcHandle) != HAL_OK)
  {
    /* Initialization Error */
    Error_Handler(); 
  }
        
  /* Clear the Tamper Flag */
  __HAL_RTC_TAMPER_CLEAR_FLAG(&RtcHandle,RTC_FLAG_TAMP1F);
  
  /*##-2- Configure RTC Tamper ###############################################*/
  /* Configure RTC Tamper */
  RTC_TamperConfig();
  
  /*##-3- Write Data on the Back Up registers ################################*/
  for(index = 0; index < BACKUP_COUNT; index++)
  {
    HAL_RTCEx_BKUPWrite(&RtcHandle,aBKPDataReg[index], 0xDF59 + (index * 0x5A));
  }
  
  /*##-4- Check Data is stored on the Back Up registers ######################*/
  for(index = 0; index < BACKUP_COUNT; index++)
  {
    if(HAL_RTCEx_BKUPRead(&RtcHandle, aBKPDataReg[index]) != (0xDF59 + (index * 0x5A)))
    {
      Error_Handler();
    }
  }
  
  /* Turn LED2 on */
  BSP_LED_On(LED2);
  
  /*##-5- Wait for the tamper button is pressed ##############################*/
  while(TamperStatus != SET);
  
  /*##-6- Deactivate the tamper ##############################################*/
  HAL_RTCEx_DeactivateTamper(&RtcHandle, RTC_TAMPER_1);
 
  /*##-7- Check Data is cleared on the Back Up registers #####################*/
  for(index = 0; index < BACKUP_COUNT; index++)
  {
    if(HAL_RTCEx_BKUPRead(&RtcHandle, aBKPDataReg[index]) != 0x00)
    {
      Error_Handler();
    }
  }
  
  /* Infinite loop */  
  while (1)
  {
    /* Toggle LED4 */
    BSP_LED_Toggle(LED4);
    
    /* Delay */
    HAL_Delay(100);
  }
}
Пример #14
0
__task void power (void)
 {
   unsigned int count =0;
   unsigned int temp;
	 static GPIO_InitTypeDef  GPIO_InitStruct;
	 GPIO_PinState bitstatus;
  
   while(1)
     {
	      GPIO_InitStruct.Pin = GPIO_PIN_2;
        GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
        GPIO_InitStruct.Pull = GPIO_PULLUP;
        GPIO_InitStruct.Speed = GPIO_SPEED_FAST;  
        HAL_GPIO_Init(GPIOC, &GPIO_InitStruct); 	  
	      bitstatus   =   HAL_GPIO_ReadPin(GPIOC,GPIO_PIN_2);	      
        if(bitstatus==GPIO_PIN_RESET)
				{			
             os_dly_wait (200);
             bitstatus   =   HAL_GPIO_ReadPin(GPIOC,GPIO_PIN_2);
					   if(bitstatus==GPIO_PIN_RESET)
						 {	 
							 
							   if(HAL_RTCEx_BKUPRead(&RtcHandle, RTC_BKP_DR6)==0)
								 {
												count =0;
											 do{
															 bitstatus   =   HAL_GPIO_ReadPin(GPIOC,GPIO_PIN_2);
															 count++;
															 if(count>5000000)
															 {       
																			 Time3Disable();
																			 GUI_Clear();                                 												 
																			 HAL_GPIO_WritePin(GPIOE,GPIO_PIN_3,GPIO_PIN_SET);  
																			 HAL_GPIO_WritePin(GPIOE,GPIO_PIN_2,GPIO_PIN_RESET);  
																			 if(zhuantskid  !=NULL)  os_tsk_delete(zhuantskid);   
																			 if(maintskid   !=NULL)  os_tsk_delete(maintskid);   
																			 if(keytskid    !=NULL)  os_tsk_delete(keytskid);  
																			 if(servertskid !=NULL)  os_tsk_delete(servertskid);  
																			 if(meuntskid !=NULL)  os_tsk_delete(meuntskid);  
																			 if(setsystemtimetskid !=NULL)  os_tsk_delete(setsystemtimetskid);  
																			 if(setledlighttskid !=NULL)  os_tsk_delete(setledlighttskid);  
																			 if(setledtimetskid !=NULL)  os_tsk_delete(setledtimetskid);  
																			 if(setsoundtskid !=NULL)  os_tsk_delete(setsoundtskid);   													 
																			 if(setworkmodetskid !=NULL)  os_tsk_delete(setworkmodetskid);  
																			 if(yushentskid !=NULL)  os_tsk_delete(yushentskid);

                                       HAL_RTCEx_BKUPWrite(&RtcHandle,RTC_BKP_DR6,1);  		// 说明是正常关机状态;

                                       														 
                                       HAL_GPIO_WritePin(GPIOG,GPIO_PIN_3,GPIO_PIN_RESET);  
																			 HAL_GPIO_WritePin(GPIOG,GPIO_PIN_2,GPIO_PIN_SET);  
                                     											 
																	 
															 } 	 
													 
												 }while(bitstatus==GPIO_PIN_RESET); 	
									}else
                  {
                         os_mut_init(mut_GLCD);
	 
												 os_mut_init(mut_Gclock);
												
												 GUI_UC_SetEncodeUTF8();   
												 
												 zhuantskid = os_tsk_create (zhuan1, 0);
												 maintskid  = os_tsk_create (Main_Task, 0);  
												 keytskid   = os_tsk_create (phase_KEY, 0);    
												 servertskid = os_tsk_create (Server_Task, 0);   
                         Time3Enable(HAL_RTCEx_BKUPRead(&RtcHandle, RTC_BKP_DR1));
                        
										     HAL_GPIO_WritePin(GPIOE,GPIO_PIN_3,GPIO_PIN_RESET);  
												 HAL_GPIO_WritePin(GPIOE,GPIO_PIN_2,GPIO_PIN_SET);  
										
                         HAL_RTCEx_BKUPWrite(&RtcHandle,RTC_BKP_DR6,0);  // 清楚掉关机状态 	
                  }										
					
	           }
	  
	      }
     
	    }    
   
 }
Пример #15
0
/**
  * @brief  Main program.
  * @param  None
  * @retval None
  */ 
int main(void)
{  
  /* STM32F4xx HAL library initialization:
       - Configure the Flash prefetch, instruction and Data caches
       - Configure the Systick to generate an interrupt each 1 msec
       - Set NVIC Group Priority to 4
       - Global MSP (MCU Support Package) initialization
     */
  HAL_Init();  
  
  /* Configure the system clock to have a system clock = 180 Mhz */
  SystemClock_Config();
  
  /* Init the STemWin GUI Library */
 BSP_SDRAM_Init(); /* Initializes the SDRAM device */
 __CRC_CLK_ENABLE(); /* Enable the CRC Module */
	
	
//	__PWR_CLK_ENABLE();
//	HAL_PWR_EnableBkUpAccess();

//	__HAL_RCC_LSE_CONFIG(RCC_LSE_BYPASS);
//	__HAL_RCC_RTC_ENABLE();
	
	/*##-1- Configure the RTC peripheral #######################################*/
  RtcHandle.Instance = RTC;
  
  /* Configure RTC prescaler and RTC data registers */
  /* RTC configured as follow:
      - Hour Format    = Format 24
      - Asynch Prediv  = Value according to source clock
      - Synch Prediv   = Value according to source clock
      - OutPut         = Output Disable
      - OutPutPolarity = High Polarity
      - OutPutType     = Open Drain */ 
  RtcHandle.Init.HourFormat = RTC_HOURFORMAT_24;
  RtcHandle.Init.AsynchPrediv = RTC_ASYNCH_PREDIV;
  RtcHandle.Init.SynchPrediv = RTC_SYNCH_PREDIV;
  RtcHandle.Init.OutPut = RTC_OUTPUT_DISABLE;
  RtcHandle.Init.OutPutPolarity = RTC_OUTPUT_POLARITY_HIGH;
  RtcHandle.Init.OutPutType = RTC_OUTPUT_TYPE_OPENDRAIN;
  
  if(HAL_RTC_Init(&RtcHandle) != HAL_OK)
  {
    /* Initialization Error */
    Error_Handler(); 
  }
   
  /*##-2- Check if Data stored in BackUp register0: No Need to reconfigure RTC#*/
  /* Read the BackUp Register 0 Data */
  if(HAL_RTCEx_BKUPRead(&RtcHandle, RTC_BKP_DR0) != 0x32F2)
  {  
    /* Configure RTC Calendar */
    RTC_CalendarConfig();
  }
  else
  {
    /* Check if the Power On Reset flag is set */  
    if(__HAL_RCC_GET_FLAG(RCC_FLAG_PORRST) != RESET)
    {
     
    }
    /* Check if Pin Reset flag is set */
    if(__HAL_RCC_GET_FLAG(RCC_FLAG_PINRST) != RESET)
    {
     
    }
    
    /* Clear Reset Flag */
    __HAL_RCC_CLEAR_RESET_FLAGS();
  }
	
  
	
  GUI_Init();  
  //GUI_Initialized = 1;
  GPIO_Config();
	if(HAL_RTCEx_BKUPRead(&RtcHandle, RTC_BKP_DR1) ==0)
	{
		 HAL_RTCEx_BKUPWrite(&RtcHandle,RTC_BKP_DR1,600);  
	}
	Time3Enable(HAL_RTCEx_BKUPRead(&RtcHandle, RTC_BKP_DR1));

  /* Activate the use of memory device feature */
  WM_SetCreateFlags(WM_CF_MEMDEV);
    
 os_sys_init (init); 
  
}
Пример #16
0
void rtcBackUpSetValue(uint32_t RegNumber, uint32_t val)
{
    HAL_RTCEx_BKUPWrite(&RtcHandle, RegNumber, val);
}