Skip to content

STM32: fix us ticker set event timestamp double ISR possibility #4632

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 29, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions targets/TARGET_STM/us_ticker_32b.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,16 @@ uint32_t us_ticker_read()
void us_ticker_set_interrupt(timestamp_t timestamp)
{
TimMasterHandle.Instance = TIM_MST;
// disable IT while we are handling the correct timestamp
__HAL_TIM_DISABLE_IT(&TimMasterHandle, TIM_IT_CC1);
// Set new output compare value
__HAL_TIM_SET_COMPARE(&TimMasterHandle, TIM_CHANNEL_1, (uint32_t)timestamp);
// Enable IT
__HAL_TIM_ENABLE_IT(&TimMasterHandle, TIM_IT_CC1);
// Check if timestamp has already passed, and if so, set the event immediately
if ((int32_t)(timestamp - TIM_MST->CNT) <= 0) {
LL_TIM_GenerateEvent_CC1(TimMasterHandle.Instance);
}
// Enable IT
__HAL_TIM_ENABLE_IT(&TimMasterHandle, TIM_IT_CC1);
}

void us_ticker_disable_interrupt(void)
Expand Down