/* Initializes the TIMx Time Base Unit peripheral according to the specified parameters in the TIM_TimeBaseInitStruct.  */
void TIM_TimeBaseInit(TIM_TypeDef *TIMx, TIM_TimeBaseInitTypeDef *TIM_TimeBaseInitStruct)
/* Initializes the TIMx Time Base Unit peripheral according to the specified parameters in the TIM_TimeBaseInitStruct.  */
void TIM_TimeBaseInit(TIM_TypeDef *TIMx, TIM_TimeBaseInitTypeDef *TIM_TimeBaseInitStruct)
{
    assert_param(IS_TIM_123458_PERIPH(TIMx)); 
    assert_param(IS_TIM_COUNTER_MODE(TIM_TimeBaseInitStruct->TIM_CounterMode));
    assert_param(IS_TIM_CKD_DIV(TIM_TimeBaseInitStruct->TIM_ClockDivision));
    TIMx->CR1 &= CR1_CKD_Mask & CR1_CounterMode_Mask;
    TIMx->CR1 |= (uint32_t)TIM_TimeBaseInitStruct->TIM_ClockDivision |
        TIM_TimeBaseInitStruct->TIM_CounterMode;
    TIMx->ARR = TIM_TimeBaseInitStruct->TIM_Period ;
    TIMx->PSC = TIM_TimeBaseInitStruct->TIM_Prescaler;
    if(*(uint32_t*)&TIMx == TIM1_BASE)	  
    {
        TIMx->RCR = TIM_TimeBaseInitStruct->TIM_RepetitionCounter;
    }
    TIMx->EGR = TIM_PSCReloadMode_Immediate;          
}