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
28
29
30
31
32
33
34
35
36
37
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
73
77
78
79
80
81
82
83
84
90
91
92
93
94
95
100
101
102
103
104
105
111
116
117
123
128
129
130
131
132
133
134
135
136
137
141
142
147
/* ... */
#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);
}{ ... }