Skip to content

Commit 413c1ba

Browse files
ABOSTMfpistm
authored andcommitted
HardwareTimer: Fix resume after pause issue introduced with G4 Cube update
New hardening has been implemented in Timer HAL (starting with G4): The new Channel state implementation prevent to restart a channel, if the channel has not been explicitly be stopped with HAL interface. Channel state is forced ready when pause() or pauseChannel() is called.
1 parent e04687b commit 413c1ba

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

cores/arduino/HardwareTimer.cpp

+16
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,13 @@ void HardwareTimer::pause()
113113

114114
// Disable timer unconditionally
115115
LL_TIM_DisableCounter(_timerObj.handle.Instance);
116+
117+
#if defined(TIM_CHANNEL_STATE_SET_ALL)
118+
/* Starting from G4, new Channel state implementation prevents to restart a channel,
119+
if the channel has not been explicitly be stopped with HAL interface */
120+
TIM_CHANNEL_STATE_SET_ALL(&(_timerObj.handle), HAL_TIM_CHANNEL_STATE_READY);
121+
TIM_CHANNEL_N_STATE_SET_ALL(&(_timerObj.handle), HAL_TIM_CHANNEL_STATE_READY);
122+
#endif
116123
}
117124

118125
/**
@@ -137,6 +144,15 @@ void HardwareTimer::pauseChannel(uint32_t channel)
137144
// Disable channel and corresponding interrupt
138145
__HAL_TIM_DISABLE_IT(&(_timerObj.handle), interrupt);
139146
LL_TIM_CC_DisableChannel(_timerObj.handle.Instance, LLChannel);
147+
#if defined(TIM_CHANNEL_STATE_SET)
148+
/* Starting from G4, new Channel state implementation prevents to restart a channel,
149+
if the channel has not been explicitly be stopped with HAL interface */
150+
if (isComplementaryChannel[channel - 1]) {
151+
TIM_CHANNEL_N_STATE_SET(&(_timerObj.handle), getChannel(channel), HAL_TIM_CHANNEL_STATE_READY);
152+
} else {
153+
TIM_CHANNEL_STATE_SET(&(_timerObj.handle), getChannel(channel), HAL_TIM_CHANNEL_STATE_READY);
154+
}
155+
#endif
140156

141157
// In case 2 channels are used, disbale also the 2nd one
142158
if (_ChannelMode[channel - 1] == TIMER_INPUT_FREQ_DUTY_MEASUREMENT) {

0 commit comments

Comments
 (0)