Skip to content

Commit

Permalink
arch/arm64/src/imx9/imx9_tpm_pwm.c: Fix re-starting PWM
Browse files Browse the repository at this point in the history
When the PWM outputs were stopped, it was not possible to re-start them

Signed-off-by: Jukka Laitinen <[email protected]>
  • Loading branch information
jlaitine committed Apr 5, 2024
1 parent 7019fbd commit 7db9c4e
Showing 1 changed file with 21 additions and 14 deletions.
35 changes: 21 additions & 14 deletions arch/arm64/src/imx9/imx9_tpm_pwm.c
Original file line number Diff line number Diff line change
Expand Up @@ -376,8 +376,29 @@ static void tpm_mux(void)

static int pwm_update_frequency(struct imx9_pwmtimer_s *priv, int freq)
{
int i;

if (freq != priv->frequency)
{
/* Start PWM on all channels if it was previously stopped */

if (freq > 0 && priv->frequency == 0)
{
/* Set the EPWM mode for all the configured channels:
*
* High-true pulses (clear output on counter match, set output
* on counter reload, clear output when counter first enabled
* or paused)
* SC[CPWMS] = 0, MSnB:MSnA = 1:0 ELSnB:ELSnA = 0
*/

for (i = 0; i < priv->n_channels; i++)
{
pwm_putreg(priv, IMX9_TPM_CXSC_OFFSET(CHMUX(priv, i)),
TPM_CXSC_MSB_MASK);
}
}

priv->period = freq > 0 ? priv->clk / freq : 0;

pwminfo("PWM%d frequency: %" PRIu32" period: %" PRIu32 "\n", priv->id,
Expand Down Expand Up @@ -660,20 +681,6 @@ struct pwm_lowerhalf_s *imx9_tpm_pwm_init(tpm_pwm_id_t pwmid)
pwm_putreg(lower, IMX9_TPM_SC_OFFSET, 1 << TPM_SC_CMOD_SHIFT);

pwminfo("PWM%d at %" PRIxPTR " configured\n", pwmid, lower->base);

/* Set the EPWM mode for all the configured channels:
*
* High-true pulses (clear output on counter match, set output
* on counter reload, clear output when counter first enabled
* or paused)
* SC[CPWMS] = 0, MSnB:MSnA = 1:0 ELSnB:ELSnA = 0
*/

for (i = 0; i < lower->n_channels; i++)
{
pwm_putreg(lower, IMX9_TPM_CXSC_OFFSET(CHMUX(lower, i)),
TPM_CXSC_MSB_MASK);
}
}
else
{
Expand Down

0 comments on commit 7db9c4e

Please sign in to comment.