STM32F769IDiscovery  1.00
uDANTE Audio Networking with STM32F7 DISCO board
stm32f7xx_hal_timebase_tim_template.c
Go to the documentation of this file.
1 
44 /* Includes ------------------------------------------------------------------*/
45 #include "stm32f7xx_hal.h"
46 
55 /* Private typedef -----------------------------------------------------------*/
56 /* Private define ------------------------------------------------------------*/
57 /* Private macro -------------------------------------------------------------*/
58 /* Private variables ---------------------------------------------------------*/
60 /* Private function prototypes -----------------------------------------------*/
61 void TIM6_DAC_IRQHandler(void);
62 /* Private functions ---------------------------------------------------------*/
63 
73 HAL_StatusTypeDef HAL_InitTick (uint32_t TickPriority)
74 {
75  RCC_ClkInitTypeDef clkconfig;
76  uint32_t uwTimclock, uwAPB1Prescaler = 0U;
77  uint32_t uwPrescalerValue = 0U;
78  uint32_t pFLatency;
79 
80  /*Configure the TIM6 IRQ priority */
81  HAL_NVIC_SetPriority(TIM6_DAC_IRQn, TickPriority ,0U);
82 
83  /* Enable the TIM6 global Interrupt */
85 
86  /* Enable TIM6 clock */
88 
89  /* Get clock configuration */
90  HAL_RCC_GetClockConfig(&clkconfig, &pFLatency);
91 
92  /* Get APB1 prescaler */
93  uwAPB1Prescaler = clkconfig.APB1CLKDivider;
94 
95  /* Compute TIM6 clock */
96  if (uwAPB1Prescaler == RCC_HCLK_DIV1)
97  {
98  uwTimclock = HAL_RCC_GetPCLK1Freq();
99  }
100  else
101  {
102  uwTimclock = 2*HAL_RCC_GetPCLK1Freq();
103  }
104 
105  /* Compute the prescaler value to have TIM6 counter clock equal to 1MHz */
106  uwPrescalerValue = (uint32_t) ((uwTimclock / 1000000U) - 1U);
107 
108  /* Initialize TIM6 */
109  TimHandle.Instance = TIM6;
110 
111  /* Initialize TIMx peripheral as follow:
112  + Period = [(TIM6CLK/1000) - 1]. to have a (1/1000) s time base.
113  + Prescaler = (uwTimclock/1000000 - 1) to have a 1MHz counter clock.
114  + ClockDivision = 0
115  + Counter direction = Up
116  */
117  TimHandle.Init.Period = (1000000U / 1000U) - 1U;
118  TimHandle.Init.Prescaler = uwPrescalerValue;
119  TimHandle.Init.ClockDivision = 0;
120  TimHandle.Init.CounterMode = TIM_COUNTERMODE_UP;
121  if(HAL_TIM_Base_Init(&TimHandle) == HAL_OK)
122  {
123  /* Start the TIM time Base generation in interrupt mode */
124  return HAL_TIM_Base_Start_IT(&TimHandle);
125  }
126 
127  /* Return function status */
128  return HAL_ERROR;
129 }
130 
137 void HAL_SuspendTick(void)
138 {
139  /* Disable TIM6 update Interrupt */
140  __HAL_TIM_DISABLE_IT(&TimHandle, TIM_IT_UPDATE);
141 }
142 
149 void HAL_ResumeTick(void)
150 {
151  /* Enable TIM6 Update interrupt */
152  __HAL_TIM_ENABLE_IT(&TimHandle, TIM_IT_UPDATE);
153 }
154 
164 {
165  HAL_IncTick();
166 }
167 
174 {
175  HAL_TIM_IRQHandler(&TimHandle);
176 }
177 
186 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
Period elapsed callback in non blocking mode.
RCC System, AHB and APB busses clock configuration structure definition.
void HAL_SuspendTick(void)
Suspend Tick increment.
#define TIM_IT_UPDATE
void HAL_RCC_GetClockConfig(RCC_ClkInitTypeDef *RCC_ClkInitStruct, uint32_t *pFLatency)
HAL_StatusTypeDef HAL_TIM_Base_Start_IT(TIM_HandleTypeDef *htim)
HAL_StatusTypeDef HAL_TIM_Base_Init(TIM_HandleTypeDef *htim)
uint32_t HAL_RCC_GetPCLK1Freq(void)
#define RCC_HCLK_DIV1
#define __HAL_RCC_TIM6_CLK_ENABLE()
void HAL_NVIC_SetPriority(IRQn_Type IRQn, uint32_t PreemptPriority, uint32_t SubPriority)
This file contains all the functions prototypes for the HAL module driver.
#define TIM6
Definition: stm32f745xx.h:1262
void HAL_NVIC_EnableIRQ(IRQn_Type IRQn)
TIM_HandleTypeDef TimHandle
void HAL_IncTick(void)
This function is called to increment a global variable "uwTick" used as application time base...
#define TIM_COUNTERMODE_UP
TIM Time Base Handle Structure definition.
TIM_TypeDef * Instance
HAL_StatusTypeDef HAL_InitTick(uint32_t TickPriority)
This function configures the TIM6 as a time base source. The time source is configured to have 1ms ti...
TIM_Base_InitTypeDef Init
#define __HAL_TIM_DISABLE_IT(__HANDLE__, __INTERRUPT__)
void HAL_ResumeTick(void)
Resume Tick increment.
HAL_StatusTypeDef
HAL Status structures definition.
#define __HAL_TIM_ENABLE_IT(__HANDLE__, __INTERRUPT__)
void HAL_TIM_IRQHandler(TIM_HandleTypeDef *htim)
void TIM6_DAC_IRQHandler(void)
This function handles TIM interrupt request.