cancel
Showing results for 
Search instead for 
Did you mean: 

STM32CubeMX failing to set PWM complment channel

este00
Associate II
Posted on May 26, 2015 at 23:26

I have an F103-Nucelo, Kiel, and want to set Tim1 with PWM on Ch2,Ch2n,Ch3,Ch3n. I have this set as correctly as I can see in STM32Cube. I have a scope and can verify the Ch2/Ch3 work perfectly. The complmenet/negative channels do not initialize however.

////////////////////Things HAL does
HAL_Init();
SystemClock_Config();
MX_GPIO_Init();
MX_TIM1_Init();
/////////////////////My code
printf (
''PWM should be running''
);
HAL_TIM_PWM_Start(&htim1,TIM_CHANNEL_2);
HAL_TIM_PWM_Start(&htim1,TIM_CHANNEL_3);

Works fine to turn on TIM1 CC2E and TIM1 CC3E which set the PWM on those channels. But I can't seem to find a clean way to enable CC2NE/CC3NE. I can do this:

TIM1->CCER |= (TIM_CCER_CC2NE | TIM_CCER_CC3NE);

But no where is that documented as how I'm supposed to go about it, nor does that seem like how the HAL would ''want'' me to. Am I just missing this option or functions somewhere? #complement #hal #pwm #timers #check-the-_ex-file
3 REPLIES 3
tech2399
Associate II
Posted on May 27, 2015 at 12:15

Hi,

Try:

HAL_TIM_PWMN_Start(&htim1,TIM_CHANNEL_2);

HAL_TIM_PWMN_Start(&htim1,TIM_CHANNEL_3);

este00
Associate II
Posted on May 27, 2015 at 18:10

I appreciate the suggestion! And yea, I feel dumb but that was the issue.

I had spent so much time looking over stm32f1xx_hal_tim.c that I had kind of forgotten to check stm32f1xx_hal_tim_ex.c..... Good one!

Thanks STM for inexplicably making another source that contains functions that would easily fit in the original. Then never mentioning for even hinting upon it's existence... Super helpful!

Amel NASRI
ST Employee
Posted on June 01, 2015 at 11:36

Thanks STM for inexplicably making another source that contains functions that would easily fit in the original. Then never mentioning for even hinting upon it's existence... Super helpful!

These fucntions are called the ''Extension APIs'' defined in UM1847 as the ones that ''provide specific and customized functions for a specific familyor a specific part number''.

Functions of TIMex driver are listed and explained in UM1850 (Description of STM32F1xx HAL drivers).

-Mayla-

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.