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
81
85
86
87
88
89
90
91
92
98
99
100
101
102
103
108
109
110
111
112
113
119
124
125
131
136
137
138
139
140
141
142
143
144
145
149
150
155
159
160
163
164
/* ... */
#include "stm32f4xx_hal.h"
/* ... */
/* ... */
Includes
TIM_HandleTypeDef TimHandle;
void TIM6_DAC_IRQHandler(void);
/* ... */
HAL_StatusTypeDef HAL_InitTick (uint32_t TickPriority)
{
RCC_ClkInitTypeDef clkconfig;
uint32_t uwTimclock, uwAPB1Prescaler = 0U;
uint32_t uwPrescalerValue = 0U;
uint32_t pFLatency;
HAL_NVIC_SetPriority(TIM6_DAC_IRQn, TickPriority ,0U);
HAL_NVIC_EnableIRQ(TIM6_DAC_IRQn);
__HAL_RCC_TIM6_CLK_ENABLE();
HAL_RCC_GetClockConfig(&clkconfig, &pFLatency);
uwAPB1Prescaler = clkconfig.APB1CLKDivider;
if (uwAPB1Prescaler == RCC_HCLK_DIV1)
{
uwTimclock = HAL_RCC_GetPCLK1Freq();
}if (uwAPB1Prescaler == RCC_HCLK_DIV1) { ... }
else
{
uwTimclock = 2*HAL_RCC_GetPCLK1Freq();
}else { ... }
uwPrescalerValue = (uint32_t) ((uwTimclock / 1000000U) - 1U);
TimHandle.Instance = TIM6;
/* ... */
TimHandle.Init.Period = (1000000U / 1000U) - 1U;
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_ERROR;
}{ ... }
/* ... */
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 TIM6_DAC_IRQHandler(void)
{
HAL_TIM_IRQHandler(&TimHandle);
}{ ... }
/* ... */
/* ... */