1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
36
37
38
39
40
41
42
43
44
45
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
86
90
91
92
93
94
95
96
97
103
104
105
106
107
108
113
114
115
116
117
118
124
129
130
136
141
142
143
144
145
146
147
148
149
150
154
155
160
164
165
168
169
/* ... */
#include "stm32f4xx_hal.h"
/* ... */
/* ... */
Includes
TIM_HandleTypeDef TimHandle;
void TIM5_IRQHandler(void);
/* ... */
HAL_StatusTypeDef HAL_InitTick (uint32_t TickPriority)
{
RCC_ClkInitTypeDef sClokConfig;
uint32_t uwTimclock, uwAPB1Prescaler = 0;
uint32_t uwPrescalerValue = 0;
uint32_t pFLatency;
__HAL_RCC_TIM5_CLK_ENABLE();
HAL_NVIC_SetPriority(TIM5_IRQn, TICK_INT_PRIORITY, 0);
HAL_NVIC_EnableIRQ(TIM5_IRQn);
HAL_NVIC_SetPriority(TIM5_IRQn, TickPriority ,0);
HAL_RCC_GetClockConfig(&sClokConfig, &pFLatency);
uwAPB1Prescaler = sClokConfig.APB1CLKDivider;
if (uwAPB1Prescaler == 0)
{
uwTimclock = HAL_RCC_GetPCLK1Freq();
}if (uwAPB1Prescaler == 0) { ... }
else
{
uwTimclock = 2*HAL_RCC_GetPCLK1Freq();
}else { ... }
uwPrescalerValue = (uint32_t) ((uwTimclock / 1000000) - 1);
TimHandle.Instance = TIM5;
/* ... */
TimHandle.Init.Period = (1000000 / 1000) - 1;
TimHandle.Init.Prescaler = uwPrescalerValue;
TimHandle.Init.ClockDivision = 0;
TimHandle.Init.CounterMode = TIM_COUNTERMODE_UP;
TimHandle.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
if(HAL_TIM_Base_Init(&TimHandle) == HAL_OK)
{
return HAL_TIM_Base_Start_IT(&TimHandle);
}if (HAL_TIM_Base_Init(&TimHandle) == HAL_OK) { ... }
return HAL_OK;
}{ ... }
/* ... */
void HAL_SuspendTick(void)
{
__HAL_TIM_DISABLE_IT(&TimHandle, TIM_IT_UPDATE);
}{ ... }
/* ... */
void HAL_ResumeTick(void)
{
__HAL_TIM_ENABLE_IT(&TimHandle, TIM_IT_UPDATE);
}{ ... }
/* ... */
void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
{
HAL_IncTick();
}{ ... }
/* ... */
void TIM5_IRQHandler(void)
{
HAL_TIM_IRQHandler(&TimHandle);
}{ ... }
/* ... */
/* ... */