Skip to content

Commit

Permalink
pwm/pwm_da1469x: Preserve timer state on frequency change.
Browse files Browse the repository at this point in the history
Read the current timer state (timer control reg) and preserve
its running state when setting frequency. The only bits that
should be set in the control register are the bits to enable
the timer in the proper mode and enable the clock.
  • Loading branch information
wes3 committed May 23, 2024
1 parent 5946fe6 commit f2b4e41
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions hw/drivers/pwm/pwm_da1469x/src/pwm_da1469x.c
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ da1469x_pwm_configure_channel(struct pwm_dev *dev, uint8_t channel,

pwm = da1469x_pwm_resolve(dev->pwm_instance_id);
if (!pwm || !pwm->in_use) {
return SYS_EINVAL;
return SYS_EINVAL;
}

mcu_gpio_set_pin_function(cfg->pin, MCU_GPIO_MODE_OUTPUT, pwm->gpio_func);
Expand Down Expand Up @@ -220,6 +220,7 @@ da1469x_pwm_set_freq(struct pwm_dev *dev, uint32_t freq)
int tim_pwm_freq;
uint32_t sys_clk_en;
uint32_t actual_freq;
uint32_t clk_reg;

pwm = da1469x_pwm_resolve(dev->pwm_instance_id);
if (!pwm || !pwm->in_use) {
Expand All @@ -232,7 +233,8 @@ da1469x_pwm_set_freq(struct pwm_dev *dev, uint32_t freq)
}

pwm->timer_regs->TIMER_PRESCALER_REG = 0;
pwm->timer_regs->TIMER_CTRL_REG = sys_clk_en;
clk_reg = pwm->timer_regs->TIMER_CTRL_REG & ~TIMER_TIMER_CTRL_REG_TIM_SYS_CLK_EN_Msk;
pwm->timer_regs->TIMER_CTRL_REG = (sys_clk_en | clk_reg);
pwm->timer_regs->TIMER_PWM_FREQ_REG = tim_pwm_freq;

pwm->freq = actual_freq;
Expand Down

0 comments on commit f2b4e41

Please sign in to comment.