STM32/STM32L4: Review of last commit -- Eliminate possible underflow

This commit is contained in:
Gregory Nutt 2017-06-13 07:05:46 -06:00
parent 7903a8a46c
commit e379491d13
2 changed files with 12 additions and 4 deletions

View File

@ -1300,8 +1300,8 @@ static int pwm_timer(FAR struct stm32_pwmtimer_s *priv,
timclk = priv->pclk / prescaler;
reload = timclk / info->frequency - 1;
if (reload < 1)
reload = timclk / info->frequency;
if (reload < 2)
{
reload = 1;
}
@ -1309,6 +1309,10 @@ static int pwm_timer(FAR struct stm32_pwmtimer_s *priv,
{
reload = 65535;
}
else
{
reload--;
}
pwminfo("TIM%u PCLK: %u frequency: %u TIMCLK: %u prescaler: %u reload: %u\n",
priv->timid, priv->pclk, info->frequency, timclk, prescaler, reload);

View File

@ -841,8 +841,8 @@ static int stm32l4pwm_timer(FAR struct stm32l4_pwmtimer_s *priv,
timclk = priv->pclk / prescaler;
reload = timclk / info->frequency - 1;
if (reload < 1)
reload = timclk / info->frequency;
if (reload < 2)
{
reload = 1;
}
@ -850,6 +850,10 @@ static int stm32l4pwm_timer(FAR struct stm32l4_pwmtimer_s *priv,
{
reload = 65535;
}
else
{
reload--;
}
pwminfo("TIM%u PCLK: %u frequency: %u TIMCLK: %u prescaler: %u reload: %u\n",
priv->timid, priv->pclk, info->frequency, timclk, prescaler, reload);