Skip to content

Commit c005781

Browse files
committed
[BLUEPILL] fix interrupt handler
1 parent fd757d3 commit c005781

File tree

1 file changed

+26
-20
lines changed
  • hal/targets/cmsis/TARGET_STM/TARGET_STM32F1/TARGET_BLUEPILL_F103C8

1 file changed

+26
-20
lines changed

hal/targets/cmsis/TARGET_STM/TARGET_STM32F1/TARGET_BLUEPILL_F103C8/hal_tick.c

Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -52,37 +52,43 @@ void timer_irq_handler(void) {
5252

5353
// Clear Update interrupt flag
5454
if (__HAL_TIM_GET_FLAG(&TimMasterHandle, TIM_FLAG_UPDATE) == SET) {
55-
__HAL_TIM_CLEAR_FLAG(&TimMasterHandle, TIM_FLAG_UPDATE);
56-
SlaveCounter++;
55+
if (__HAL_TIM_GET_IT_SOURCE(&TimMasterHandle, TIM_IT_UPDATE) == SET) {
56+
__HAL_TIM_CLEAR_IT(&TimMasterHandle, TIM_IT_UPDATE);
57+
SlaveCounter++;
58+
}
5759
}
5860

5961
// Channel 1 for mbed timeout
6062
if (__HAL_TIM_GET_FLAG(&TimMasterHandle, TIM_FLAG_CC1) == SET) {
61-
__HAL_TIM_CLEAR_FLAG(&TimMasterHandle, TIM_FLAG_CC1);
62-
if (oc_rem_part > 0) {
63-
set_compare(oc_rem_part); // Finish the remaining time left
64-
oc_rem_part = 0;
65-
} else {
66-
if (oc_int_part > 0) {
67-
set_compare(0xFFFF);
68-
oc_rem_part = cnt_val; // To finish the counter loop the next time
69-
oc_int_part--;
63+
if (__HAL_TIM_GET_IT_SOURCE(&TimMasterHandle, TIM_IT_CC1) == SET) {
64+
__HAL_TIM_CLEAR_IT(&TimMasterHandle, TIM_IT_CC1);
65+
if (oc_rem_part > 0) {
66+
set_compare(oc_rem_part); // Finish the remaining time left
67+
oc_rem_part = 0;
7068
} else {
71-
us_ticker_irq_handler();
69+
if (oc_int_part > 0) {
70+
set_compare(0xFFFF);
71+
oc_rem_part = cnt_val; // To finish the counter loop the next time
72+
oc_int_part--;
73+
} else {
74+
us_ticker_irq_handler();
75+
}
7276
}
7377
}
7478
}
7579

7680
// Channel 2 for HAL tick
7781
if (__HAL_TIM_GET_FLAG(&TimMasterHandle, TIM_FLAG_CC2) == SET) {
78-
__HAL_TIM_CLEAR_FLAG(&TimMasterHandle, TIM_FLAG_CC2);
79-
uint32_t val = __HAL_TIM_GetCounter(&TimMasterHandle);
80-
if ((val - PreviousVal) >= HAL_TICK_DELAY) {
81-
// Increment HAL variable
82-
HAL_IncTick();
83-
// Prepare next interrupt
84-
__HAL_TIM_SetCompare(&TimMasterHandle, TIM_CHANNEL_2, val + HAL_TICK_DELAY);
85-
PreviousVal = val;
82+
if (__HAL_TIM_GET_IT_SOURCE(&TimMasterHandle, TIM_IT_CC2) == SET) {
83+
__HAL_TIM_CLEAR_IT(&TimMasterHandle, TIM_IT_CC2);
84+
uint32_t val = __HAL_TIM_GetCounter(&TimMasterHandle);
85+
if ((val - PreviousVal) >= HAL_TICK_DELAY) {
86+
// Increment HAL variable
87+
HAL_IncTick();
88+
// Prepare next interrupt
89+
__HAL_TIM_SetCompare(&TimMasterHandle, TIM_CHANNEL_2, val + HAL_TICK_DELAY);
90+
PreviousVal = val;
91+
}
8692
}
8793
}
8894
}

0 commit comments

Comments
 (0)