Skip to content

Commit 70b9109

Browse files
gautierg-stdanieldegrasse
authored andcommitted
drivers: pwm: stm32: fix four channel pwm capture
With the four-channel-capture-support property enabled, the STM32 PWM driver was missing every other frames during PWM capture. The counter values are now reset just after getting the pulse and the period of the cycle, instead of waiting the next interrupt to do so, and thus missing a cycle. Signed-off-by: Guillaume Gautier <[email protected]>
1 parent 79f599a commit 70b9109

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

drivers/pwm/pwm_stm32.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -625,7 +625,6 @@ static int pwm_stm32_enable_capture(const struct device *dev, uint32_t channel)
625625

626626
LL_TIM_CC_EnableChannel(cfg->timer, ch2ll[channel - 1]);
627627
LL_TIM_CC_EnableChannel(cfg->timer, ch2ll[complimentary_channel[channel] - 1]);
628-
LL_TIM_EnableIT_UPDATE(cfg->timer);
629628
LL_TIM_GenerateEvent_UPDATE(cfg->timer);
630629

631630
return 0;
@@ -731,6 +730,8 @@ static void pwm_stm32_isr(const struct device *dev)
731730
cpt->pulse = get_channel_capture[complimentary_channel[cpt->channel] - 1]
732731
(cfg->timer);
733732
cpt->period = get_channel_capture[cpt->channel - 1](cfg->timer);
733+
/* Reset the counter manually for next cycle */
734+
LL_TIM_GenerateEvent_UPDATE(cfg->timer);
734735
}
735736

736737
clear_capture_interrupt[cpt->channel - 1](cfg->timer);
@@ -749,7 +750,7 @@ static void pwm_stm32_isr(const struct device *dev)
749750
pwm_stm32_disable_capture(dev, cpt->channel);
750751
} else {
751752
cpt->overflows = 0u;
752-
cpt->state = CAPTURE_STATE_WAIT_FOR_PULSE_START;
753+
cpt->state = CAPTURE_STATE_WAIT_FOR_PERIOD_END;
753754
}
754755

755756
if (cpt->callback != NULL) {

0 commit comments

Comments
 (0)