cancel
Showing results for 
Search instead for 
Did you mean: 

STM32CubeMX (4.3.0) HAL driver. Start TIM8 as PWM with OCx and OCxN channels

rm2399
Associate III
Posted on August 13, 2014 at 17:50

With the HAL_TIM_PWM_Start() command CCxNE the flag is not set in the register CCER.

In the initialisation the function HAL_TIM_PWM_ConfigChannel() call TIM_OCx_SetConfig(). Here the flags CCxE and CCxNE in register CCER are reseted.

In the function HAL_TIM_PWM_Start() only the flag CCxE ist setted.

If I set the flag CCxNE in the debugger, the PWM works fine.

Is this a bug

or

do I have to

configure

something else

?

Attached the files generated by STM32CubeMX. The main.c file was supplemented  with the timer start.

#stm32-complementary-pwm-ccxne
3 REPLIES 3
stm32cube-t
Senior III
Posted on September 16, 2014 at 14:32

Hello,

There is an issue in current STM32CubeMX version that does not initialize HAL init structure ''optional'' parameters. They must be properly initialized otherwise the register gets corrupted with random data pulled out from the stack.

This will be fixed in next STM32CubeMX release.

As a workaround, you need to manually add the initialization code for this fields:

sConfigOC.OCNPolarity = TIM_OCNPOLARITY_HIGH;

sConfigOC.OCNIdleState = TIM_OCNIDLESTATE_RESET;

Best Regards

With the HAL_TIM_PWM_Start() command CCxNE the flag is not set in the register CCER.

In the initialisation the function HAL_TIM_PWM_ConfigChannel() call TIM_OCx_SetConfig(). Here the flags CCxE and CCxNE in register CCER are reseted.

In the function HAL_TIM_PWM_Start() only the flag CCxE ist setted.

If I set the flag CCxNE in the debugger, the PWM works fine.

Is this a bug

or

do I have to

configure

something else

?

Attached the files generated by STM32CubeMX. The main.c file was supplemented  with the timer start.
Nickname1997_O
Associate II
Posted on September 17, 2014 at 10:17

Hi

the ''HAL_TIM_PWM_start(..) '' command  I see in your main.c is only dedicated to the ''positive channel''.

To use the complementary channel , and consequently to set the CCxNE bit of CCER register , another start command have to be called 

-> HAL_TIMex_PWMN_Start(&htim8,TIM_CHANNEL_3);

This function is located in stm32f4xx_hal_tim_ex.h and an include of this .h file is already done in stm32f4xx_hal_tim.h so no need to add it again

  /* USER CODE BEGIN 2 */

  HAL_TIM_Base_Start(&htim6);

  HAL_TIM_PWM_Start(&htim8,TIM_CHANNEL_3);

 

HAL_TIMex_PWMN_Start(&htim8,TIM_CHANNEL_3);

  /* USER CODE END 2 */

hope this help

rm2399
Associate III
Posted on September 23, 2014 at 09:21

Hi

the

additional command

HAL_TIMex_PWMN_Start(&htim8,TIM_CHANNEL_3);

helps.

But in the current

HAL

version, it

must

be written as:

HAL_TIM

E

x_PWMN_Start(&htim8,TIM_CHANNEL_3);

Thanks to all

for help