Skip to content

Commit 1df53a4

Browse files
committed
fix(hardwaretimer): resume depending of channels mode
Allow to properly set handle state. Start TIM base only if required. Signed-off-by: Frederic Pillon <[email protected]>
1 parent 29f0f68 commit 1df53a4

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

Diff for: libraries/SrcWrapper/src/HardwareTimer.cpp

+10-7
Original file line numberDiff line numberDiff line change
@@ -217,20 +217,23 @@ void HardwareTimer::pauseChannel(uint32_t channel)
217217
*/
218218
void HardwareTimer::resume(void)
219219
{
220+
bool baseStart = true;
221+
for (uint8_t i = 1; i <= TIMER_CHANNELS; i++) {
222+
if (_ChannelMode[i - 1] != TIMER_OUTPUT_DISABLED) {
223+
resumeChannel(i);
224+
baseStart = false;
225+
}
226+
}
220227
// Clear flag and enable IT
221228
if (callbacks[0]) {
222229
__HAL_TIM_CLEAR_FLAG(&(_timerObj.handle), TIM_FLAG_UPDATE);
223230
__HAL_TIM_ENABLE_IT(&(_timerObj.handle), TIM_IT_UPDATE);
231+
}
224232

225-
// Start timer in Time base mode. Required when there is no channel used but only update interrupt.
233+
// Start timer in Time base mode. Required when there is no channel used but only update interrupt.
234+
if (baseStart && (!LL_TIM_IsEnabledCounter(_timerObj.handle.Instance))) {
226235
HAL_TIM_Base_Start(&(_timerObj.handle));
227236
}
228-
229-
// Resume all channels
230-
resumeChannel(1);
231-
resumeChannel(2);
232-
resumeChannel(3);
233-
resumeChannel(4);
234237
}
235238

236239
/**

0 commit comments

Comments
 (0)