Skip to content

Commit 74c29cb

Browse files
committed
Remove code related to timer channel 2
1 parent 91e826d commit 74c29cb

File tree

3 files changed

+13
-104
lines changed

3 files changed

+13
-104
lines changed

targets/TARGET_STM/hal_tick_16b.c

Lines changed: 0 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@
1818
// A 16-bit timer is used
1919
#if TIM_MST_16BIT
2020

21-
#define DEBUG_TICK 0 // Set to 1 to toggle a pin (see below which pin) at each tick
22-
2321
extern TIM_HandleTypeDef TimMasterHandle;
2422

2523
volatile uint32_t PreviousVal = 0;
@@ -49,23 +47,6 @@ void timer_oc_irq_handler(void)
4947
us_ticker_irq_handler();
5048
}
5149
}
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-
}
6950
}
7051

7152
// Reconfigure the HAL tick using a standard timer instead of systick.
@@ -95,22 +76,10 @@ HAL_StatusTypeDef HAL_InitTick(uint32_t TickPriority)
9576
#endif
9677
HAL_TIM_Base_Init(&TimMasterHandle);
9778

98-
//LL_TIM_EnableUpdateEvent(TimMasterHandle.Instance);
99-
10079
// Configure output compare channel 1 for mbed timeout (enabled later when used)
10180
HAL_TIM_OC_Start(&TimMasterHandle, TIM_CHANNEL_1);
10281

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
11282
// Output compare channel 1 interrupt for mbed timeout
113-
// Output compare channel 2 interrupt for HAL tick
11483
#if defined(TARGET_STM32F0)
11584
NVIC_SetVector(TIM_MST_UP_IRQ, (uint32_t)timer_update_irq_handler);
11685
NVIC_EnableIRQ(TIM_MST_UP_IRQ);
@@ -123,9 +92,6 @@ HAL_StatusTypeDef HAL_InitTick(uint32_t TickPriority)
12392
NVIC_EnableIRQ(TIM_MST_IRQ);
12493
#endif
12594

126-
// Enable interrupts
127-
__HAL_TIM_ENABLE_IT(&TimMasterHandle, TIM_IT_CC2); // For HAL tick
128-
12995
// Enable timer
13096
HAL_TIM_Base_Start(&TimMasterHandle);
13197

@@ -135,29 +101,7 @@ HAL_StatusTypeDef HAL_InitTick(uint32_t TickPriority)
135101
TIM_MST_DBGMCU_FREEZE;
136102
#endif
137103

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-
148104
return HAL_OK;
149105
}
150106

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-
163107
#endif // TIM_MST_16BIT

targets/TARGET_STM/hal_tick_32b.c

Lines changed: 0 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@
1818
// A 32-bit timer is used
1919
#if !TIM_MST_16BIT
2020

21-
#define DEBUG_TICK 0 // Set to 1 to toggle a pin (see below which pin) at each tick
22-
2321
extern TIM_HandleTypeDef TimMasterHandle;
2422

2523
volatile uint32_t PreviousVal = 0;
@@ -35,22 +33,6 @@ void timer_irq_handler(void)
3533
us_ticker_irq_handler();
3634
}
3735
}
38-
39-
// Channel 2 for HAL tick
40-
if (__HAL_TIM_GET_FLAG(&TimMasterHandle, TIM_FLAG_CC2) == SET) {
41-
if (__HAL_TIM_GET_IT_SOURCE(&TimMasterHandle, TIM_IT_CC2) == SET) {
42-
__HAL_TIM_CLEAR_IT(&TimMasterHandle, TIM_IT_CC2);
43-
uint32_t val = __HAL_TIM_GET_COUNTER(&TimMasterHandle);
44-
if ((val - PreviousVal) >= HAL_TICK_DELAY) {
45-
// Prepare next interrupt
46-
__HAL_TIM_SET_COMPARE(&TimMasterHandle, TIM_CHANNEL_2, val + HAL_TICK_DELAY);
47-
PreviousVal = val;
48-
#if DEBUG_TICK > 0
49-
HAL_GPIO_TogglePin(GPIOB, GPIO_PIN_6);
50-
#endif
51-
}
52-
}
53-
}
5436
}
5537

5638
// Reconfigure the HAL tick using a standard timer instead of systick.
@@ -108,41 +90,13 @@ HAL_StatusTypeDef HAL_InitTick(uint32_t TickPriority)
10890
// Channel 1 for mbed timeout
10991
HAL_TIM_OC_Start(&TimMasterHandle, TIM_CHANNEL_1);
11092

111-
// Channel 2 for HAL tick
112-
HAL_TIM_OC_Start(&TimMasterHandle, TIM_CHANNEL_2);
113-
PreviousVal = __HAL_TIM_GET_COUNTER(&TimMasterHandle);
114-
__HAL_TIM_SET_COMPARE(&TimMasterHandle, TIM_CHANNEL_2, PreviousVal + HAL_TICK_DELAY);
115-
__HAL_TIM_ENABLE_IT(&TimMasterHandle, TIM_IT_CC2);
116-
11793
// Freeze timer on stop/breakpoint
11894
// Define the FREEZE_TIMER_ON_DEBUG macro in mbed_app.json for example
11995
#if !defined(NDEBUG) && defined(FREEZE_TIMER_ON_DEBUG) && defined(TIM_MST_DBGMCU_FREEZE)
12096
TIM_MST_DBGMCU_FREEZE;
12197
#endif
12298

123-
#if DEBUG_TICK > 0
124-
__HAL_RCC_GPIOB_CLK_ENABLE();
125-
GPIO_InitTypeDef GPIO_InitStruct;
126-
GPIO_InitStruct.Pin = GPIO_PIN_6;
127-
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
128-
GPIO_InitStruct.Pull = GPIO_PULLUP;
129-
GPIO_InitStruct.Speed = GPIO_SPEED_FAST;
130-
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
131-
#endif
132-
13399
return HAL_OK;
134100
}
135101

136-
/* NOTE: must be called with interrupts disabled! */
137-
void HAL_SuspendTick(void)
138-
{
139-
__HAL_TIM_DISABLE_IT(&TimMasterHandle, TIM_IT_CC2);
140-
}
141-
142-
/* NOTE: must be called with interrupts disabled! */
143-
void HAL_ResumeTick(void)
144-
{
145-
__HAL_TIM_ENABLE_IT(&TimMasterHandle, TIM_IT_CC2);
146-
}
147-
148102
#endif // !TIM_MST_16BIT

targets/TARGET_STM/stm_common.c

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,18 @@
11
#include "hal/us_ticker_api.h"
22

3-
// Overwrite default HAL function
3+
// Overwrite default HAL functions defined as "weak"
4+
45
uint32_t HAL_GetTick()
56
{
6-
return ticker_read_us(get_us_ticker_data()) / 1000;
7+
return ticker_read_us(get_us_ticker_data()) / 1000; // 1 ms tick is required for ST HAL
8+
}
9+
10+
void HAL_SuspendTick(void)
11+
{
12+
// Do nothing
13+
}
14+
15+
void HAL_ResumeTick(void)
16+
{
17+
// Do nothing
718
}

0 commit comments

Comments
 (0)