Skip to content

Commit 0591b2b

Browse files
committed
STM32: fix us ticker set event timestamp
While we are handling new timestamp, disable ticker's interrupt.
1 parent cbfb234 commit 0591b2b

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

targets/TARGET_STM/us_ticker_32b.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,16 @@ uint32_t us_ticker_read()
4444
void us_ticker_set_interrupt(timestamp_t timestamp)
4545
{
4646
TimMasterHandle.Instance = TIM_MST;
47+
// disable IT while we are handling the correct timestamp
48+
__HAL_TIM_DISABLE_IT(&TimMasterHandle, TIM_IT_CC1);
4749
// Set new output compare value
4850
__HAL_TIM_SET_COMPARE(&TimMasterHandle, TIM_CHANNEL_1, (uint32_t)timestamp);
49-
// Enable IT
50-
__HAL_TIM_ENABLE_IT(&TimMasterHandle, TIM_IT_CC1);
5151
// Check if timestamp has already passed, and if so, set the event immediately
5252
if ((int32_t)(timestamp - TIM_MST->CNT) <= 0) {
5353
LL_TIM_GenerateEvent_CC1(TimMasterHandle.Instance);
5454
}
55+
// Enable IT
56+
__HAL_TIM_ENABLE_IT(&TimMasterHandle, TIM_IT_CC1);
5557
}
5658

5759
void us_ticker_disable_interrupt(void)

0 commit comments

Comments
 (0)