From 3f44e8208204e55d5d479e3b717b786b502987f3 Mon Sep 17 00:00:00 2001 From: Frederic Pillon Date: Tue, 19 Nov 2024 11:15:55 +0100 Subject: [PATCH] fix(timer): pause the channel before new PWM config Signed-off-by: Frederic Pillon --- libraries/SrcWrapper/src/HardwareTimer.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/libraries/SrcWrapper/src/HardwareTimer.cpp b/libraries/SrcWrapper/src/HardwareTimer.cpp index 7bb1da5dbf..ecaf44309b 100644 --- a/libraries/SrcWrapper/src/HardwareTimer.cpp +++ b/libraries/SrcWrapper/src/HardwareTimer.cpp @@ -936,6 +936,9 @@ void HardwareTimer::setPWM(uint32_t channel, uint32_t pin, uint32_t frequency, u */ void HardwareTimer::setPWM(uint32_t channel, PinName pin, uint32_t frequency, uint32_t dutycycle, callback_function_t PeriodCallback, callback_function_t CompareCallback) { + if (isRunningChannel(channel)) { + pauseChannel(channel); + } setMode(channel, TIMER_OUTPUT_COMPARE_PWM1, pin); setOverflow(frequency, HERTZ_FORMAT); setCaptureCompare(channel, dutycycle, PERCENT_COMPARE_FORMAT);