STMicroelectronics / STM32CubeF7

STM32Cube MCU Full Package for the STM32F7 series - (HAL + LL Drivers, CMSIS Core, CMSIS Device, MW libraries plus a set of Projects running on all boards provided by ST (Nucleo, Evaluation and Discovery Kits))
Other
342 stars 197 forks source link

Timers: HAL_TIM_PWM_Stop() disable timer even channel 5 or channel 6 are enabled #106

Closed KamilDuljas closed 1 week ago

KamilDuljas commented 1 year ago

TIM_CCER_CCxE_MASK makro should be contain 6 channels, not 4. Missing TIM_CCER_CC5E and TIM_CCER_CC6E image

Example:

HAL_TIM_PWM_Start(&htim1,TIM_CHANNEL_1);
HAL_TIM_PWM_Start(&htim1,TIM_CHANNEL_2);
HAL_TIM_PWM_Start(&htim1,TIM_CHANNEL_5);

HAL_TIM_PWM_Stop(&htim1,TIM_CHANNEL_1);
// TIM_CR1_CEN is '1' (TIM_BDTR_MOE is '1' for  advanced timers)
HAL_TIM_PWM_Stop(&htim1,TIM_CHANNEL_2);
// TIM_CR1_CEN is '0' but CHANNEL 5 is still active!!!
HAL_TIM_PWM_Stop(&htim1,TIM_CHANNEL_5);

The issue related to macros TIM_CCER_CCxE_MASK and:

/**
  * @brief  Disable the TIM peripheral.
  * @param  __HANDLE__ TIM handle
  * @retval None
  */
#define __HAL_TIM_DISABLE(__HANDLE__) \
  do { \
    if (((__HANDLE__)->Instance->CCER & TIM_CCER_CCxE_MASK) == 0UL) \
    { \
      if(((__HANDLE__)->Instance->CCER & TIM_CCER_CCxNE_MASK) == 0UL) \
      { \
        (__HANDLE__)->Instance->CR1 &= ~(TIM_CR1_CEN); \
      } \
    } \
  } while(0)

/**
  * @brief  Disable the TIM main Output.
  * @param  __HANDLE__ TIM handle
  * @retval None
  * @note The Main Output Enable of a timer instance is disabled only if all the CCx and CCxN channels have been
  *       disabled
  */
#define __HAL_TIM_MOE_DISABLE(__HANDLE__) \
  do { \
    if (((__HANDLE__)->Instance->CCER & TIM_CCER_CCxE_MASK) == 0UL) \
    { \
      if(((__HANDLE__)->Instance->CCER & TIM_CCER_CCxNE_MASK) == 0UL) \
      { \
        (__HANDLE__)->Instance->BDTR &= ~(TIM_BDTR_MOE); \
      } \
    } \
  } while(0)

Also please look closer TIM_CCER_CCxNE_MASK

KamilDuljas commented 1 year ago

H7 repo is also affected.

KRASTM commented 1 month ago

Hello @KamilDuljas,

Thank you for the report.

Regarding the issue, and based on the RM either for F7 or H7:

With regards,

KRASTM commented 1 month ago

ST Internal Reference: 195184

TOUNSTM commented 1 week ago

Fixed in ea67690c22fcf4683e8a1cda948b43cd0c77aa11