1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
24
25
26
27
28
29
30
31
32
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
63
67
68
69
70
71
72
73
74
80
81
82
83
84
85
86
87
108
109
110
111
112
113
119
124
125
131
136
/* ... */
#include "stm32f4xx_hal.h"
#include "stm32f4xx_hal_tim.h"
Includes
TIM_HandleTypeDef htim6;
/* ... */
HAL_StatusTypeDef HAL_InitTick(uint32_t TickPriority)
{
RCC_ClkInitTypeDef clkconfig;
uint32_t uwTimclock, uwAPB1Prescaler = 0U;
uint32_t uwPrescalerValue = 0U;
uint32_t pFLatency;
HAL_StatusTypeDef status;
__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 = 2UL * HAL_RCC_GetPCLK1Freq();
}else { ... }
uwPrescalerValue = (uint32_t) ((uwTimclock / 1000000U) - 1U);
htim6.Instance = TIM6;
/* ... */
htim6.Init.Period = (1000000U / 1000U) - 1U;
htim6.Init.Prescaler = uwPrescalerValue;
htim6.Init.ClockDivision = 0;
htim6.Init.CounterMode = TIM_COUNTERMODE_UP;
htim6.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
status = HAL_TIM_Base_Init(&htim6);
if (status == HAL_OK)
{
status = HAL_TIM_Base_Start_IT(&htim6);
if (status == HAL_OK)
{
HAL_NVIC_EnableIRQ(TIM6_DAC_IRQn);
if (TickPriority < (1UL << __NVIC_PRIO_BITS))
{
HAL_NVIC_SetPriority(TIM6_DAC_IRQn, TickPriority, 0U);
uwTickPrio = TickPriority;
}if (TickPriority < (1UL << __NVIC_PRIO_BITS)) { ... }
else
{
status = HAL_ERROR;
}else { ... }
}if (status == HAL_OK) { ... }
}if (status == HAL_OK) { ... }
return status;
}{ ... }
/* ... */
void HAL_SuspendTick(void)
{
__HAL_TIM_DISABLE_IT(&htim6, TIM_IT_UPDATE);
}{ ... }
/* ... */
void HAL_ResumeTick(void)
{
__HAL_TIM_ENABLE_IT(&htim6, TIM_IT_UPDATE);
}{ ... }