KugleFirmware/Src/stm32h7xx_hal_timebase_tim.c
/**
  * @brief  This function configures the TIM16 as a time base source. 
  *         The time source is configured  to have 1ms time base with a dedicated 
  *         Tick interrupt priority. 
  * @note   This function is called  automatically at the beginning of program after
  *         reset by HAL_Init() or at any time when clock is configured, by HAL_RCC_ClockConfig(). 
  * @param  TickPriority: Tick interrupt priority.
  * @retval HAL status
  */
@brief  This function configures the TIM16 as a time base source.
The time source is configured  to have 1ms time base with a dedicated
Tick interrupt priority.
@note   This function is called  automatically at the beginning of program after
reset by HAL_Init() or at any time when clock is configured, by HAL_RCC_ClockConfig().
@param  TickPriority: Tick interrupt priority.
@retval HAL status
@brief This function configures the TIM16 as a time base source . The time source is configured to have 1ms time base with a dedicated Tick interrupt priority . @note This function is called automatically at the beginning of program after reset by HAL_Init () or at any time when clock is configured by HAL_RCC_ClockConfig () . @param TickPriority : Tick interrupt priority . @retval HAL status
HAL_StatusTypeDef HAL_InitTick(uint32_t TickPriority)
{
  RCC_ClkInitTypeDef    clkconfig;
  uint32_t              uwTimclock = 0;
  uint32_t              uwPrescalerValue = 0;
  uint32_t              pFLatency;
  HAL_NVIC_SetPriority(TIM16_IRQn, TickPriority ,0); 
  HAL_NVIC_EnableIRQ(TIM16_IRQn); 
  __HAL_RCC_TIM16_CLK_ENABLE();
  HAL_RCC_GetClockConfig(&clkconfig, &pFLatency);
  uwTimclock = 2*HAL_RCC_GetPCLK2Freq();
  frequency = 10000; 
  uwPrescalerValue = (uint32_t) ((uwTimclock / frequency) - 1);
  htim16.Instance = TIM16;
  htim16.Init.Period = (10000 / 1) - 1;
  htim16.Init.Prescaler = uwPrescalerValue;
  htim16.Init.ClockDivision = 0;
  htim16.Init.CounterMode = TIM_COUNTERMODE_UP;
  if(HAL_TIM_Base_Init(&htim16) == HAL_OK)
  {
    return HAL_TIM_Base_Start_IT(&htim16);
  }
  return HAL_ERROR;
}
HAL_StatusTypeDef HAL_InitTick ( uint32_t TickPriority ) { RCC_ClkInitTypeDef clkconfig ; uint32_t uwTimclock = 0 ; uint32_t uwPrescalerValue = 0 ; uint32_t pFLatency ; HAL_NVIC_SetPriority ( TIM16_IRQn , TickPriority , 0 ) ; HAL_NVIC_EnableIRQ ( TIM16_IRQn ) ; __HAL_RCC_TIM16_CLK_ENABLE ( ) ; HAL_RCC_GetClockConfig ( & clkconfig , & pFLatency ) ; uwTimclock = 2 * HAL_RCC_GetPCLK2Freq ( ) ; frequency = 10000 ; uwPrescalerValue = ( uint32_t ) ( ( uwTimclock / frequency ) - 1 ) ; htim16 . Instance = TIM16 ; htim16 . Init . Period = ( 10000 / 1 ) - 1 ; htim16 . Init . Prescaler = uwPrescalerValue ; htim16 . Init . ClockDivision = 0 ; htim16 . Init . CounterMode = TIM_COUNTERMODE_UP ; if ( HAL_TIM_Base_Init ( & htim16 ) == HAL_OK ) { return HAL_TIM_Base_Start_IT ( & htim16 ) ; } return HAL_ERROR ; }
@brief  This function configures the TIM16 as a time base source.
@brief This function configures the TIM16 as a time base source .
/*Configure the TIM16 IRQ priority */ /* Enable the TIM16 global Interrupt */ /* Enable TIM16 clock */ /* Get clock configuration */ /* Compute TIM16 clock */ // 10 kHz /* Compute the prescaler value to have TIM16 counter clock equal to 10 kHz */ /* Initialize TIM16 */ /* Initialize TIMx peripheral as follow:
  + Period = [(TIM16CLK/1000) - 1]. to have a (1/1000) s time base.
  + Prescaler = (uwTimclock/1000000 - 1) to have a 1MHz counter clock.
  + ClockDivision = 0
  + Counter direction = Up
  */ // Modified by Thomas: Configure timer to overflow every second, thus firing an interrupt @ 1 Hz rate /* Start the TIM time Base generation in interrupt mode */ /* Return function status */