Skip to content

Commit

Permalink
fix(hardwaretimer): resume depending of channels mode
Browse files Browse the repository at this point in the history
Allow to properly set handle state.
Start TIM base only if required.

Signed-off-by: Frederic Pillon <[email protected]>
  • Loading branch information
fpistm committed Nov 21, 2024
1 parent 29f0f68 commit 1df53a4
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions libraries/SrcWrapper/src/HardwareTimer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -217,20 +217,23 @@ void HardwareTimer::pauseChannel(uint32_t channel)
*/
void HardwareTimer::resume(void)
{
bool baseStart = true;
for (uint8_t i = 1; i <= TIMER_CHANNELS; i++) {
if (_ChannelMode[i - 1] != TIMER_OUTPUT_DISABLED) {
resumeChannel(i);
baseStart = false;
}
}
// Clear flag and enable IT
if (callbacks[0]) {
__HAL_TIM_CLEAR_FLAG(&(_timerObj.handle), TIM_FLAG_UPDATE);
__HAL_TIM_ENABLE_IT(&(_timerObj.handle), TIM_IT_UPDATE);
}

// Start timer in Time base mode. Required when there is no channel used but only update interrupt.
// Start timer in Time base mode. Required when there is no channel used but only update interrupt.
if (baseStart && (!LL_TIM_IsEnabledCounter(_timerObj.handle.Instance))) {
HAL_TIM_Base_Start(&(_timerObj.handle));
}

// Resume all channels
resumeChannel(1);
resumeChannel(2);
resumeChannel(3);
resumeChannel(4);
}

/**
Expand Down

0 comments on commit 1df53a4

Please sign in to comment.