STM32L4xx_HAL_Driver  1.14.0
stm32l4xx_hal_timebase_tim_template.c
Go to the documentation of this file.
1 
41 /* Includes ------------------------------------------------------------------*/
42 #include "stm32l4xx_hal.h"
43 
52 /* Private typedef -----------------------------------------------------------*/
53 /* Private define ------------------------------------------------------------*/
54 /* Private macro -------------------------------------------------------------*/
55 /* Private variables ---------------------------------------------------------*/
57 /* Private function prototypes -----------------------------------------------*/
58 void TIM6_DAC_IRQHandler(void);
59 /* Private functions ---------------------------------------------------------*/
60 
70 HAL_StatusTypeDef HAL_InitTick(uint32_t TickPriority)
71 {
72  RCC_ClkInitTypeDef clkconfig;
73  uint32_t uwTimclock, uwAPB1Prescaler = 0U;
74  uint32_t uwPrescalerValue = 0U;
75  uint32_t pFLatency;
76 
77  /* Configure the TIM6 IRQ priority */
78  HAL_NVIC_SetPriority(TIM6_DAC_IRQn, TickPriority, 0U);
79 
80  /* Enable the TIM6 global Interrupt */
81  HAL_NVIC_EnableIRQ(TIM6_DAC_IRQn);
82 
83  /* Enable TIM6 clock */
84  __HAL_RCC_TIM6_CLK_ENABLE();
85 
86  /* Get clock configuration */
87  HAL_RCC_GetClockConfig(&clkconfig, &pFLatency);
88 
89  /* Get APB1 prescaler */
90  uwAPB1Prescaler = clkconfig.APB1CLKDivider;
91 
92  /* Compute TIM6 clock */
93  if (uwAPB1Prescaler == RCC_HCLK_DIV1)
94  {
95  uwTimclock = HAL_RCC_GetPCLK1Freq();
96  }
97  else
98  {
99  uwTimclock = 2*HAL_RCC_GetPCLK1Freq();
100  }
101 
102  /* Compute the prescaler value to have TIM6 counter clock equal to 1MHz */
103  uwPrescalerValue = (uint32_t) ((uwTimclock / 1000000U) - 1U);
104 
105  /* Initialize TIM6 */
106  TimHandle.Instance = TIM6;
107 
108  /* Initialize TIMx peripheral as follow:
109  + Period = [(TIM6CLK/1000) - 1]. to have a (1/1000) s time base.
110  + Prescaler = (uwTimclock/1000000 - 1) to have a 1MHz counter clock.
111  + ClockDivision = 0
112  + Counter direction = Up
113  */
114  TimHandle.Init.Period = (1000000U / 1000U) - 1U;
115  TimHandle.Init.Prescaler = uwPrescalerValue;
116  TimHandle.Init.ClockDivision = 0;
117  TimHandle.Init.CounterMode = TIM_COUNTERMODE_UP;
118  TimHandle.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
120  {
121  /* Start the TIM time Base generation in interrupt mode */
123  }
124 
125  /* Return function status */
126  return HAL_ERROR;
127 }
128 
135 void HAL_SuspendTick(void)
136 {
137  /* Disable TIM6 update interrupt */
138  __HAL_TIM_DISABLE_IT(&TimHandle, TIM_IT_UPDATE);
139 }
140 
147 void HAL_ResumeTick(void)
148 {
149  /* Enable TIM6 update interrupt */
150  __HAL_TIM_ENABLE_IT(&TimHandle, TIM_IT_UPDATE);
151 }
152 
162 {
163  HAL_IncTick();
164 }
165 
172 {
174 }
175 
184 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
HAL_StatusTypeDef HAL_TIM_Base_Start_IT(TIM_HandleTypeDef *htim)
Starts the TIM Base generation in interrupt mode.
void TIM6_DAC_IRQHandler(void)
This function handles TIM interrupt request.
void HAL_SuspendTick(void)
Suspend Tick increment.
This file contains all the functions prototypes for the HAL module driver.
void HAL_TIM_IRQHandler(TIM_HandleTypeDef *htim)
This function handles TIM interrupts requests.
void HAL_ResumeTick(void)
Resume Tick increment.
HAL_StatusTypeDef HAL_TIM_Base_Init(TIM_HandleTypeDef *htim)
Initializes the TIM Time base Unit according to the specified parameters in the TIM_HandleTypeDef and...
void HAL_RCC_GetClockConfig(RCC_ClkInitTypeDef *RCC_ClkInitStruct, uint32_t *pFLatency)
Configure the RCC_ClkInitStruct according to the internal RCC configuration registers.
return HAL_OK
void HAL_IncTick(void)
This function is called to increment a global variable "uwTick" used as application time base...
void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
Period elapsed callback in non blocking mode.
void HAL_NVIC_EnableIRQ(IRQn_Type IRQn)
Enable a device specific interrupt in the NVIC interrupt controller.
RCC System, AHB and APB busses clock configuration structure definition.
void HAL_NVIC_SetPriority(IRQn_Type IRQn, uint32_t PreemptPriority, uint32_t SubPriority)
Set the priority of an interrupt.
TIM_HandleTypeDef TimHandle
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...
struct __TIM_HandleTypeDef else typedef struct endif TIM_HandleTypeDef
TIM Time Base Handle Structure definition.
uint32_t HAL_RCC_GetPCLK1Freq(void)
Return the PCLK1 frequency.