18
18
// A 16-bit timer is used
19
19
#if TIM_MST_16BIT
20
20
21
- #define DEBUG_TICK 0 // Set to 1 to toggle a pin (see below which pin) at each tick
22
-
23
21
extern TIM_HandleTypeDef TimMasterHandle ;
24
22
25
23
volatile uint32_t PreviousVal = 0 ;
@@ -49,23 +47,6 @@ void timer_oc_irq_handler(void)
49
47
us_ticker_irq_handler ();
50
48
}
51
49
}
52
-
53
- // Channel 2 for HAL tick
54
- if (__HAL_TIM_GET_FLAG (& TimMasterHandle , TIM_FLAG_CC2 ) == SET ) {
55
-
56
- if (__HAL_TIM_GET_IT_SOURCE (& TimMasterHandle , TIM_IT_CC2 ) == SET ) {
57
- __HAL_TIM_CLEAR_IT (& TimMasterHandle , TIM_IT_CC2 );
58
- uint32_t val = __HAL_TIM_GET_COUNTER (& TimMasterHandle );
59
- if ((val - PreviousVal ) >= HAL_TICK_DELAY ) {
60
- // Prepare next interrupt
61
- __HAL_TIM_SET_COMPARE (& TimMasterHandle , TIM_CHANNEL_2 , val + HAL_TICK_DELAY );
62
- PreviousVal = val ;
63
- #if DEBUG_TICK > 0
64
- HAL_GPIO_TogglePin (GPIOB , GPIO_PIN_6 );
65
- #endif
66
- }
67
- }
68
- }
69
50
}
70
51
71
52
// Reconfigure the HAL tick using a standard timer instead of systick.
@@ -95,22 +76,10 @@ HAL_StatusTypeDef HAL_InitTick(uint32_t TickPriority)
95
76
#endif
96
77
HAL_TIM_Base_Init (& TimMasterHandle );
97
78
98
- //LL_TIM_EnableUpdateEvent(TimMasterHandle.Instance);
99
-
100
79
// Configure output compare channel 1 for mbed timeout (enabled later when used)
101
80
HAL_TIM_OC_Start (& TimMasterHandle , TIM_CHANNEL_1 );
102
81
103
- // Configure output compare channel 2 for HAL tick
104
- HAL_TIM_OC_Start (& TimMasterHandle , TIM_CHANNEL_2 );
105
- PreviousVal = __HAL_TIM_GET_COUNTER (& TimMasterHandle );
106
- __HAL_TIM_SET_COMPARE (& TimMasterHandle , TIM_CHANNEL_2 , PreviousVal + HAL_TICK_DELAY );
107
-
108
-
109
-
110
- // Configure interrupts
111
- // Update interrupt used for 32-bit counter
112
82
// Output compare channel 1 interrupt for mbed timeout
113
- // Output compare channel 2 interrupt for HAL tick
114
83
#if defined(TARGET_STM32F0 )
115
84
NVIC_SetVector (TIM_MST_UP_IRQ , (uint32_t )timer_update_irq_handler );
116
85
NVIC_EnableIRQ (TIM_MST_UP_IRQ );
@@ -123,9 +92,6 @@ HAL_StatusTypeDef HAL_InitTick(uint32_t TickPriority)
123
92
NVIC_EnableIRQ (TIM_MST_IRQ );
124
93
#endif
125
94
126
- // Enable interrupts
127
- __HAL_TIM_ENABLE_IT (& TimMasterHandle , TIM_IT_CC2 ); // For HAL tick
128
-
129
95
// Enable timer
130
96
HAL_TIM_Base_Start (& TimMasterHandle );
131
97
@@ -135,29 +101,7 @@ HAL_StatusTypeDef HAL_InitTick(uint32_t TickPriority)
135
101
TIM_MST_DBGMCU_FREEZE ;
136
102
#endif
137
103
138
- #if DEBUG_TICK > 0
139
- __HAL_RCC_GPIOB_CLK_ENABLE ();
140
- GPIO_InitTypeDef GPIO_InitStruct ;
141
- GPIO_InitStruct .Pin = GPIO_PIN_6 ;
142
- GPIO_InitStruct .Mode = GPIO_MODE_OUTPUT_PP ;
143
- GPIO_InitStruct .Pull = GPIO_PULLUP ;
144
- GPIO_InitStruct .Speed = GPIO_SPEED_FAST ;
145
- HAL_GPIO_Init (GPIOB , & GPIO_InitStruct );
146
- #endif
147
-
148
104
return HAL_OK ;
149
105
}
150
106
151
- /* NOTE: must be called with interrupts disabled! */
152
- void HAL_SuspendTick (void )
153
- {
154
- __HAL_TIM_DISABLE_IT (& TimMasterHandle , TIM_IT_CC2 );
155
- }
156
-
157
- /* NOTE: must be called with interrupts disabled! */
158
- void HAL_ResumeTick (void )
159
- {
160
- __HAL_TIM_ENABLE_IT (& TimMasterHandle , TIM_IT_CC2 );
161
- }
162
-
163
107
#endif // TIM_MST_16BIT
0 commit comments