STM32F4 PWM Hal interrupt config error

ChibiOS public support forum for topics related to the STMicroelectronics STM32 family of micro-controllers.

Moderator: RoccoMarco

Post Reply
tecnologic
Posts: 124
Joined: Tue Jan 10, 2012 8:42 am
Has thanked: 21 times
Been thanked: 5 times

STM32F4 PWM Hal interrupt config error

Post by tecnologic »

HI again,

seems i am the only one using the ADC and pwm drivers on Stm32 at maximum.

in the TIMv1 driver this line is missing when configuring registers

Code: Select all

pwmp->tim->DIER   = pwmp->config->dier;   /* DIER settings.               */


regards

Tec
User avatar
Giovanni
Site Admin
Posts: 14892
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: STM32F4 PWM Hal interrupt config error

Post by Giovanni »

Hi,

Fixed as big #534, there was a similar problem in the ICU driver too.

Giovanni
tecnologic
Posts: 124
Joined: Tue Jan 10, 2012 8:42 am
Has thanked: 21 times
Been thanked: 5 times

Re: STM32F4 PWM Hal interrupt config error

Post by tecnologic »

Hi Giovanni,

i found one small copy and paste error within the bugfix
line 610 of pwm_lld. is

Code: Select all

pwmp->tim->DIER   = pwmp->config->dier &  /* DMA-related DIER settings.   */
                      ~STM32_TIM_DIER_IRQ_MASK

which kills the settigns of dier with

Code: Select all

&~STM32_TIM_DIER_IRQ_MASK
, removing the ~ solves the problem.

Regards

Tec
User avatar
Giovanni
Site Admin
Posts: 14892
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: STM32F4 PWM Hal interrupt config error

Post by Giovanni »

It is intentional, you are not supposed to enable interrupts by yourself using DIER, that setting is only for DMAs. Interrupts are enabled by pwmEnableChannel(). However there was another problem preventing the periodic callback.

Committed a fix but will test tomorrow, it's to late now.

Code: Select all

   /**
    * @brief TIM DIER register initialization data.
    * @note  The value of this field should normally be equal to zero.
    * @note  Only the DMA-related bits can be specified in this field.
    */
   uint32_t                 dier;


Giovanni
tecnologic
Posts: 124
Joined: Tue Jan 10, 2012 8:42 am
Has thanked: 21 times
Been thanked: 5 times

Re: STM32F4 PWM Hal interrupt config error

Post by tecnologic »

Ok, i miss interpreted this setting. I will pull the changes in the evening and test them on my HW.

Thanks
tecnologic
Posts: 124
Joined: Tue Jan 10, 2012 8:42 am
Has thanked: 21 times
Been thanked: 5 times

Re: STM32F4 PWM Hal interrupt config error

Post by tecnologic »

Code: Select all

   /* Changing channel duty cycle on the fly.*/

 #if STM32_TIM_MAX_CHANNELS <= 4

   pwmp->tim->CCR[channel] = width;

+  pwmp->tim->DIER |= (2 << channel);

 #else

   if (channel <= 4)

     pwmp->tim->CCR[channel] = width;

+   pwmp->tim->DIER |= (2 << channel);

   else

     pwmp->tim->CCXR[channel - 4] = width;

+   pwmp->tim->DIER |= (2 << (channel - 4));

 #endif

 }



This fix in pwm_lld_enable was missing. with that it works.

@OffTopic: i tested the QEI driver posted in the forum some weeks ago, it works fine for me out of the box. with an 10000 step quad encoder. may be it can be added to the hal?

Regards
Tec
User avatar
Giovanni
Site Admin
Posts: 14892
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: STM32F4 PWM Hal interrupt config error

Post by Giovanni »

Hi,

In 3.0 the API changed, the notifications have to be explicitly enabled by calling pwmEnablePeriodicNotification(), the function pwmEnableChannel() does not enable notifications by itself. Example:

Code: Select all

  pwmEnableChannel(&PWMD1, 0, PWM_PERCENTAGE_TO_WIDTH(&PWMD1, 7500));
  pwmEnableChannelNotification(&PWMD1, 0);


The point of the change is to be able to run very fast PWMs and, only when needed, enable the callback, synchronize with the front and then disable the callback again.

In the old model interrupts were always enabled if callbacks were defined, that was bad because all the interrupts.

Functions added:

Code: Select all

  void pwmEnablePeriodicNotification(PWMDriver *pwmp);
  void pwmDisablePeriodicNotification(PWMDriver *pwmp);
  void pwmEnableChannelNotification(PWMDriver *pwmp, pwmchannel_t channel);
  void pwmDisableChannelNotification(PWMDriver *pwmp, pwmchannel_t channel);


Giovanni
tecnologic
Posts: 124
Joined: Tue Jan 10, 2012 8:42 am
Has thanked: 21 times
Been thanked: 5 times

Re: STM32F4 PWM Hal interrupt config error

Post by tecnologic »

OH Ok,

Changed and works.

Thanks for the hint.
Post Reply