drivers: pwm: pwm_stm32: reset timer using RCC before initialization

If a timer is left running on an stm32mp1, (most likely) on the next run
the timer is stuck.
A simple timer reset before initialization fixes the issue.

Signed-off-by: Sean Nyekjaer <sean@geanix.com>
This commit is contained in:
Sean Nyekjaer 2023-06-23 08:24:07 +02:00 committed by Fabio Baltieri
commit 25d496949f
2 changed files with 11 additions and 1 deletions

View file

@ -9,6 +9,7 @@ config PWM_STM32
depends on DT_HAS_ST_STM32_PWM_ENABLED
select USE_STM32_LL_TIM
select USE_STM32_LL_RCC if SOC_SERIES_STM32F4X || SOC_SERIES_STM32F7X || SOC_SERIES_STM32H7X
select RESET
help
This option enables the PWM driver for STM32 family of
processors. Say y if you wish to use PWM port on STM32

View file

@ -14,6 +14,7 @@
#include <stm32_ll_tim.h>
#include <zephyr/drivers/pwm.h>
#include <zephyr/drivers/pinctrl.h>
#include <zephyr/drivers/reset.h>
#include <zephyr/device.h>
#include <zephyr/kernel.h>
#include <zephyr/init.h>
@ -53,6 +54,8 @@ struct pwm_stm32_capture_data {
struct pwm_stm32_data {
/** Timer clock (Hz). */
uint32_t tim_clk;
/* Reset controller device configuration */
const struct reset_dt_spec reset;
#ifdef CONFIG_PWM_CAPTURE
struct pwm_stm32_capture_data capture;
#endif /* CONFIG_PWM_CAPTURE */
@ -686,6 +689,9 @@ static int pwm_stm32_init(const struct device *dev)
return r;
}
/* Reset timer to default state using RCC */
(void)reset_line_toggle_dt(&data->reset);
/* configure pinmux */
r = pinctrl_apply_state(cfg->pcfg, PINCTRL_STATE_DEFAULT);
if (r < 0) {
@ -764,7 +770,10 @@ static void pwm_stm32_irq_config_func_##index(const struct device *dev) \
#define PWM_DEVICE_INIT(index) \
static struct pwm_stm32_data pwm_stm32_data_##index; \
static struct pwm_stm32_data pwm_stm32_data_##index = { \
.reset = RESET_DT_SPEC_GET(PWM(index)), \
}; \
\
IRQ_CONFIG_FUNC(index) \
\
PINCTRL_DT_INST_DEFINE(index); \