1 /* USER CODE BEGIN Header */
\r
3 ******************************************************************************
\r
4 * @file stm32l4xx_hal_timebase_TIM.c
\r
5 * @brief HAL time base based on the hardware TIM.
\r
6 ******************************************************************************
\r
9 * <h2><center>© Copyright (c) 2019 STMicroelectronics.
\r
10 * All rights reserved.</center></h2>
\r
12 * This software component is licensed by ST under BSD 3-Clause license,
\r
13 * the "License"; You may not use this file except in compliance with the
\r
14 * License. You may obtain a copy of the License at:
\r
15 * opensource.org/licenses/BSD-3-Clause
\r
17 ******************************************************************************
\r
19 /* USER CODE END Header */
\r
21 /* Includes ------------------------------------------------------------------*/
\r
22 #include "stm32l4xx_hal.h"
\r
23 #include "stm32l4xx_hal_tim.h"
\r
25 /* Private typedef -----------------------------------------------------------*/
\r
26 /* Private define ------------------------------------------------------------*/
\r
27 /* Private macro -------------------------------------------------------------*/
\r
28 /* Private variables ---------------------------------------------------------*/
\r
29 TIM_HandleTypeDef htim6;
\r
30 /* Private function prototypes -----------------------------------------------*/
\r
31 /* Private functions ---------------------------------------------------------*/
\r
34 * @brief This function configures the TIM6 as a time base source.
\r
35 * The time source is configured to have 1ms time base with a dedicated
\r
36 * Tick interrupt priority.
\r
37 * @note This function is called automatically at the beginning of program after
\r
38 * reset by HAL_Init() or at any time when clock is configured, by HAL_RCC_ClockConfig().
\r
39 * @param TickPriority: Tick interrupt priority.
\r
40 * @retval HAL status
\r
42 HAL_StatusTypeDef HAL_InitTick(uint32_t TickPriority)
\r
44 RCC_ClkInitTypeDef clkconfig;
\r
45 uint32_t uwTimclock = 0;
\r
46 uint32_t uwPrescalerValue = 0;
\r
49 /*Configure the TIM6 IRQ priority */
\r
50 HAL_NVIC_SetPriority(TIM6_DAC_IRQn, TickPriority ,0);
\r
52 /* Enable the TIM6 global Interrupt */
\r
53 HAL_NVIC_EnableIRQ(TIM6_DAC_IRQn);
\r
55 /* Enable TIM6 clock */
\r
56 __HAL_RCC_TIM6_CLK_ENABLE();
\r
58 /* Get clock configuration */
\r
59 HAL_RCC_GetClockConfig(&clkconfig, &pFLatency);
\r
61 /* Compute TIM6 clock */
\r
62 uwTimclock = HAL_RCC_GetPCLK1Freq();
\r
64 /* Compute the prescaler value to have TIM6 counter clock equal to 1MHz */
\r
65 uwPrescalerValue = (uint32_t) ((uwTimclock / 1000000) - 1);
\r
67 /* Initialize TIM6 */
\r
68 htim6.Instance = TIM6;
\r
70 /* Initialize TIMx peripheral as follow:
\r
71 + Period = [(TIM6CLK/1000) - 1]. to have a (1/1000) s time base.
\r
72 + Prescaler = (uwTimclock/1000000 - 1) to have a 1MHz counter clock.
\r
74 + Counter direction = Up
\r
76 htim6.Init.Period = (1000000 / 1000) - 1;
\r
77 htim6.Init.Prescaler = uwPrescalerValue;
\r
78 htim6.Init.ClockDivision = 0;
\r
79 htim6.Init.CounterMode = TIM_COUNTERMODE_UP;
\r
80 if(HAL_TIM_Base_Init(&htim6) == HAL_OK)
\r
82 /* Start the TIM time Base generation in interrupt mode */
\r
83 return HAL_TIM_Base_Start_IT(&htim6);
\r
86 /* Return function status */
\r
91 * @brief Suspend Tick increment.
\r
92 * @note Disable the tick increment by disabling TIM6 update interrupt.
\r
96 void HAL_SuspendTick(void)
\r
98 /* Disable TIM6 update Interrupt */
\r
99 __HAL_TIM_DISABLE_IT(&htim6, TIM_IT_UPDATE);
\r
103 * @brief Resume Tick increment.
\r
104 * @note Enable the tick increment by Enabling TIM6 update interrupt.
\r
108 void HAL_ResumeTick(void)
\r
110 /* Enable TIM6 Update interrupt */
\r
111 __HAL_TIM_ENABLE_IT(&htim6, TIM_IT_UPDATE);
\r
114 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
\r