cancel
Showing results for 
Search instead for 
Did you mean: 

STM32G030 CHxN issue

MaxEE
Associate II

Hello there. I am working on STM32G030 based FW. It appeared the TIM1x_CH1N doesn't work. I found out this part of code doesn't initialize negative channel(stm32g0xx_hal_tim.c).

MaxEE_0-1731076406357.png

Moreover it may skip all channels configurations. It seems to be a hard coded part that initializes only positive channel with defined CxP and CxN options if so it really skip user predefined ones. 

 

MaxEE_1-1731076681034.png

Could you fix this issue and update HAL driver sources?  

Thank you in advice.

1 ACCEPTED SOLUTION

Accepted Solutions
Sarra.S
ST Employee

Hello @MaxEE

Although I'm not fully sure I grasped the issue, what I understood is that TIM_CCxChannelCmd is not taking into consideration TIM_CCxN_ENABLE, so when calling HAL_TIM_PWM_Start, it only starts the positive channel -Correct me if I'm mistaken

However, I would like to draw your attention to the HAL_TIMEx_PWMN_Start macro, which starts the PWM generation on the complementary output, it indeed uses TIM_CCxN_ENABLE to enable the complementary PWM output. 

TIM_CCxNChannelCmd(htim->Instance, Channel, TIM_CCxN_ENABLE);

 

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.

View solution in original post

7 REPLIES 7
SofLit
ST Employee

Hello @MaxEE and welcome to the community,


@MaxEE wrote:

I found out this part of code doesn't initialize negative channel(stm32g0xx_hal_tim.c).

 

 What do you mean by doesn't initialize negative channel? could you please elaborate?

 


@MaxEE wrote:

Moreover it may skip all channels configurations. It seems to be a hard coded part that initializes only positive channel with defined CxP and CxN options if so it really skip user predefined ones. 

 

MaxEE_1-1731076681034.png

Could you fix this issue and update HAL driver sources?  


The second part of your question is more related to CubeMx. What do you mean by hardcoded? in HAL? or option fixed in CubeMx?

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.

Whatever the configuration are TIM16_CH1N doesn't works. It always put 0x1 to CCER register yet if I set TIM16_CH1N only as an output there should be 0x4 or 0xC. I suppose it happens since TIM_CCx_ENABLE equals 0x1 which is used in hal driver function("TIM_CCxChannelCmd" run from "HAL_TIM_PWM_Start" function).

Here comes the second question, Why doesn't built-in device configuration tools change TIM_CCx_ENABLE according to the user configurations or there should be another way to set CCER register including user configuration in the hal driver. And as a result TIM16_CH1 is always on and TIM16_CH1N is always off.

So I requested to update hal driver sources to solve this issue.

MaxEE
Associate II

It seems to be 0x4 according to my configuration(maybe 0xc it depends on "OC1N active high" meaning that is specified in the spec).

It should've set right combination inside the driver like (TIM_CCx_ENABLE | TIM_CCxN_ENABLE).
MaxEE_0-1731081670976.png

 

 

 

Sarra.S
ST Employee

Hello @MaxEE

Although I'm not fully sure I grasped the issue, what I understood is that TIM_CCxChannelCmd is not taking into consideration TIM_CCxN_ENABLE, so when calling HAL_TIM_PWM_Start, it only starts the positive channel -Correct me if I'm mistaken

However, I would like to draw your attention to the HAL_TIMEx_PWMN_Start macro, which starts the PWM generation on the complementary output, it indeed uses TIM_CCxN_ENABLE to enable the complementary PWM output. 

TIM_CCxNChannelCmd(htim->Instance, Channel, TIM_CCxN_ENABLE);

 

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.

Hi @Sarra.S Could you clarify in which file HAL_TIMEx_PWMN_Start  are? I cannot find that one in my stm32g0xx_hal_tim.c/h.

 

it's in the stm32g0xx_hal_tim_ex.c

SarraS_0-1731505398629.png

 

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.

Hmm...

I see there are right functions depends on my configuration which is located in the stm32g0xx_hal_tim_ex.c file. Will check it.

I managed the issue by skipping hal driver and configured tim16 via registers as a spec shows.

Anyway, thank you,  really appreciate it. I hope I haven't wasted your time.

 

Thank you!