Skip to main content
Explorer
November 8, 2024
Solved

STM32G030 CHxN issue

  • November 8, 2024
  • 3 replies
  • 1554 views

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.

    This topic has been closed for replies.
    Best answer by Sarra.S

    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);

     

    3 replies

    Technical Moderator
    November 8, 2024

    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?

    MaxEEAuthor
    Explorer
    November 8, 2024

    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.

    MaxEEAuthor
    Explorer
    November 8, 2024

    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.SAnswer
    ST Employee
    November 12, 2024

    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);

     

    MaxEEAuthor
    Explorer
    November 13, 2024

    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.

     

    ST Employee
    November 13, 2024

    it's in the stm32g0xx_hal_tim_ex.c

    SarraS_0-1731505398629.png