STMicroelectronics / STM32CubeF4

STM32Cube MCU Full Package for the STM32F4 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
824 stars 408 forks source link

PWM oversight on STM32CubeMX + HAL combination #167

Open okz opened 8 months ago

okz commented 8 months ago

Although CubeMX, gives the impression that PWM generation on complementary channels is possible, with options such as PWM_Generation CH1N, the HAL PWM Start API doesn't support it.

The HAL HAL_TIM_PWM_Start call only enables the standard channels for PWM. This is despite, autogenerated CubeMX code setting the GPIO for the complementary channels, and not the standard ones.

HAL_TIM_PWM_Start, really should accept TIM_CHANNEL_1N etc

image


/**
  * @brief  Starts the PWM signal generation.
  * @param  htim TIM handle
  * @param  Channel TIM Channels to be enabled
  *          This parameter can be one of the following values:
  *            @arg TIM_CHANNEL_1: TIM Channel 1 selected
  *            @arg TIM_CHANNEL_2: TIM Channel 2 selected
  *            @arg TIM_CHANNEL_3: TIM Channel 3 selected
  *            @arg TIM_CHANNEL_4: TIM Channel 4 selected
  * @retval HAL status
  */
HAL_StatusTypeDef HAL_TIM_PWM_Start(TIM_HandleTypeDef *htim, uint32_t Channel)
{
  uint32_t tmpsmcr;

  /* Check the parameters */
  assert_param(IS_TIM_CCX_INSTANCE(htim->Instance, Channel));

  /* Check the TIM channel state */
  if (TIM_CHANNEL_STATE_GET(htim, Channel) != HAL_TIM_CHANNEL_STATE_READY)
  {
    return HAL_ERROR;
  }

  /* Set the TIM channel state */
  TIM_CHANNEL_STATE_SET(htim, Channel, HAL_TIM_CHANNEL_STATE_BUSY);

  /* Enable the Capture compare channel */

 // !! 
//  !!
// Can only enable a standard channel, and not the complimentary channel that CubeMX autogenerated code has setup

TIM_CCxChannelCmd(htim->Instance, Channel, TIM_CCx_ENABLE);
RJMSTM commented 8 months ago

Hello @avisconti,

Thank you for this report. We will get back to you as soon as we analyze it further. This may take some time. Thank you for your comprehension.

With regards,

RJMSTM commented 7 months ago

Hello @okz,

First thank you for contribution, second is not indeed to enable the complementary channel in HAL_TIM_PWM_Start. I have reproduced your configuration with STM32WB55 and I found that enabling the complementary channel as mentioned in RM0434 is to set CC1NE bit. image

In the autogenerated CubeMX code in MX_TIM1_Init function you find HAL_TIM_PWM_ConfigChannel API and within this API you find TIM_OC1_SetConfig and CC1NE is set to 1

image

I hope I've been able to clarify your request, thank you once more for your contribution. We are looking forward to reading from you again.

With regards, Rania

okz commented 7 months ago

Hi Rania,

Do you mean:

i) You were able to reproduce the problem? ii) or you were able to get it working correctly ?

the reason I am confused, is you mention:

"TIM_OC1_SetConfig and CC1NE is set to 1"

But the screenshot shows CC1NE is still 0, which may have been confused with CC1NP, which is now 1

Kind regards, Oz

RJMSTM commented 7 months ago

Hello @okz, in fact, HAL_TIM_PWM_Start enable CC1NE with TIM_CCxNChannelCmd(htim->Instance, Channel, TIM_CCxN_ENABLE); image

Regards, Rania

RJMSTM commented 2 weeks ago

Hello,

Any update please!!

Regards