STM32F4xx HAL Documentation
Hardware Abstraction Layer for STM32F4 familiy
Loading...
Searching...
No Matches
stm32f4xx_hal_timebase_tim_template.c
Go to the documentation of this file.
1
25/* Includes ------------------------------------------------------------------*/
26#include "stm32f4xx_hal.h"
27
36/* Private typedef -----------------------------------------------------------*/
37/* Private define ------------------------------------------------------------*/
38/* Private macro -------------------------------------------------------------*/
39/* Private variables ---------------------------------------------------------*/
41/* Private function prototypes -----------------------------------------------*/
42void TIM6_DAC_IRQHandler(void);
43/* Private functions ---------------------------------------------------------*/
44
54HAL_StatusTypeDef HAL_InitTick (uint32_t TickPriority)
55{
56 RCC_ClkInitTypeDef clkconfig;
57 uint32_t uwTimclock, uwAPB1Prescaler = 0U;
58 uint32_t uwPrescalerValue = 0U;
59 uint32_t pFLatency;
60 HAL_StatusTypeDef status;
61
62 /* Enable TIM6 clock */
64
65 /* Get clock configuration */
66 HAL_RCC_GetClockConfig(&clkconfig, &pFLatency);
67
68 /* Get APB1 prescaler */
69 uwAPB1Prescaler = clkconfig.APB1CLKDivider;
70
71 /* Compute TIM6 clock */
72 if (uwAPB1Prescaler == RCC_HCLK_DIV1)
73 {
74 uwTimclock = HAL_RCC_GetPCLK1Freq();
75 }
76 else
77 {
78 uwTimclock = 2 * HAL_RCC_GetPCLK1Freq();
79 }
80
81 /* Compute the prescaler value to have TIM6 counter clock equal to 1MHz */
82 uwPrescalerValue = (uint32_t) ((uwTimclock / 1000000U) - 1U);
83
84 /* Initialize TIM6 */
85 TimHandle.Instance = TIM6;
86
87 /* Initialize TIMx peripheral as follow:
88 + Period = [(TIM6CLK/1000) - 1]. to have a (1/1000) s time base.
89 + Prescaler = (uwTimclock/1000000 - 1) to have a 1MHz counter clock.
90 + ClockDivision = 0
91 + Counter direction = Up
92 */
93 TimHandle.Init.Period = (1000000U / 1000U) - 1U;
94 TimHandle.Init.Prescaler = uwPrescalerValue;
99 if (status == HAL_OK)
100 {
101 /* Start the TIM time Base generation in interrupt mode */
103 if (status == HAL_OK)
104 {
105 /* Enable the TIM6 global Interrupt */
106 HAL_NVIC_EnableIRQ(TIM6_DAC_IRQn);
107
108 if (TickPriority < (1UL << __NVIC_PRIO_BITS))
109 {
110 /* Enable the TIM6 global Interrupt */
111 HAL_NVIC_SetPriority(TIM6_DAC_IRQn, TickPriority, 0);
112 uwTickPrio = TickPriority;
113 }
114 else
115 {
116 status = HAL_ERROR;
117 }
118 }
119 }
120
121 /* Return function status */
122 return status;
123}
124
131{
132 /* Disable TIM6 update Interrupt */
134}
135
142{
143 /* Enable TIM6 Update interrupt */
145}
146
159
168
void HAL_NVIC_SetPriority(IRQn_Type IRQn, uint32_t PreemptPriority, uint32_t SubPriority)
Sets the priority of an interrupt.
void HAL_NVIC_EnableIRQ(IRQn_Type IRQn)
Enables a device specific interrupt in the NVIC interrupt controller.
void HAL_IncTick(void)
This function is called to increment a global variable "uwTick" used as application time base.
uint32_t uwTickPrio
void TIM6_DAC_IRQHandler(void)
This function handles TIM interrupt request.
void HAL_ResumeTick(void)
Resume Tick increment.
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...
void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
Period elapsed callback in non blocking mode.
TIM_HandleTypeDef TimHandle
void HAL_SuspendTick(void)
Suspend Tick increment.
#define __HAL_RCC_TIM6_CLK_ENABLE()
#define RCC_HCLK_DIV1
uint32_t HAL_RCC_GetPCLK1Freq(void)
Returns the PCLK1 frequency.
void HAL_RCC_GetClockConfig(RCC_ClkInitTypeDef *RCC_ClkInitStruct, uint32_t *pFLatency)
Configures the RCC_ClkInitStruct according to the internal RCC configuration registers.
#define TIM_AUTORELOAD_PRELOAD_DISABLE
#define TIM_COUNTERMODE_UP
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...
HAL_StatusTypeDef HAL_TIM_Base_Start_IT(TIM_HandleTypeDef *htim)
Starts the TIM Base generation in interrupt mode.
void HAL_TIM_IRQHandler(TIM_HandleTypeDef *htim)
This function handles TIM interrupts requests.
#define __HAL_TIM_DISABLE_IT(__HANDLE__, __INTERRUPT__)
Disable the specified TIM interrupt.
#define __HAL_TIM_ENABLE_IT(__HANDLE__, __INTERRUPT__)
Enable the specified TIM interrupt.
#define TIM_IT_UPDATE
This file contains all the functions prototypes for the HAL module driver.
HAL_StatusTypeDef
HAL Status structures definition
@ HAL_ERROR
@ HAL_OK
RCC System, AHB and APB busses clock configuration structure definition.
TIM Time Base Handle Structure definition.
TIM_Base_InitTypeDef Init