Skip to content

HardwareTimer: set callback before enabling interrupt #835

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
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
4 changes: 2 additions & 2 deletions cores/arduino/HardwareTimer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -848,13 +848,13 @@ void HardwareTimer::setInterruptPriority(uint32_t preemptPriority, uint32_t subP
*/
void HardwareTimer::attachInterrupt(void (*callback)(HardwareTimer *))
{
callbacks[0] = callback;
if (callback != NULL) {
// Clear flag before enabling IT
__HAL_TIM_CLEAR_FLAG(&(_timerObj.handle), TIM_FLAG_UPDATE);
// Enable update interrupt only if callback is valid
__HAL_TIM_ENABLE_IT(&(_timerObj.handle), TIM_IT_UPDATE);
}
callbacks[0] = callback;
}

/**
Expand Down Expand Up @@ -885,13 +885,13 @@ void HardwareTimer::attachInterrupt(uint32_t channel, void (*callback)(HardwareT
Error_Handler(); // only channel 1..4 have an interrupt
}

callbacks[channel] = callback;
if (callback != NULL) {
// Clear flag before enabling IT
__HAL_TIM_CLEAR_FLAG(&(_timerObj.handle), interrupt);
// Enable interrupt corresponding to channel, only if callback is valid
__HAL_TIM_ENABLE_IT(&(_timerObj.handle), interrupt);
}
callbacks[channel] = callback;
}

/**
Expand Down