Skip to main content
Explorer II
October 1, 2025
Solved

How a GPIO pin binds to a PWM channel

  • October 1, 2025
  • 2 replies
  • 266 views

Hi Sir,

I tried to refer to the PWM example:

~\stm32cubeh7-v1-12-0\STM32Cube_FW_H7_V1.12.0\Projects\STM32H743I-EVAL\Examples\TIM\TIM_PWMOutput

 

I see the four GPIO pins are initialized:

Jimmy_Ma_1-1759295806483.png

 

And I see the four PWM channels are setup:

Jimmy_Ma_0-1759295773760.png

 

But I can't find the code where each GPIO pin is bound to each PWM channel or the ISR where each GPIO is toggled whenever a PWM channel interrupt occurs.

 

Please advise. Thanks.

 

Jimmy

 

    This topic has been closed for replies.
    Best answer by waclawek.jan

    @mƎALLEm,

    you probably meant the AF mapping table in Datasheet, rather than in Reference Manual.

    @Jimmy_Ma,

    As said above, read the Datasheet for your STM32, and the GPIO chapter in Reference Manual.

    waclawekjan_0-1759304825210.png

    waclawekjan_1-1759304869111.png

    Unfortunately, CubeMX generated some "magic values" for you and Cube/HAL hides rest of the details, so it's not visible from the code you presented, how exactly are the GPIO set. Fortunately, Cube/HAL is open source, so you can read it yourself and/or single-step through it, while observing the GPIO registers, to get a grip on what's going on.

    JW

     

    2 replies

    Technical Moderator
    October 1, 2025

    Hello, 

    In next time please share the code and use </> instead of sharing screenshots of the code.

    I’m not sure I understood the question but .Alternate member of the GPIO structure is the one responsible of linking the timer functions or any other peripheral functions to the GPIOs.

    You need to refer to the reference manual of the product and there is a table showing tha mapping of these alternate functions on the GPIOs.

     

    Super User
    October 1, 2025

    @mƎALLEm,

    you probably meant the AF mapping table in Datasheet, rather than in Reference Manual.

    @Jimmy_Ma,

    As said above, read the Datasheet for your STM32, and the GPIO chapter in Reference Manual.

    waclawekjan_0-1759304825210.png

    waclawekjan_1-1759304869111.png

    Unfortunately, CubeMX generated some "magic values" for you and Cube/HAL hides rest of the details, so it's not visible from the code you presented, how exactly are the GPIO set. Fortunately, Cube/HAL is open source, so you can read it yourself and/or single-step through it, while observing the GPIO registers, to get a grip on what's going on.

    JW

     

    Jimmy_MaAuthor
    Explorer II
    October 1, 2025

    @mƎALLEm @waclawek.jan 

     

    It seems that the alternate function is specified here when configuring a GPIO:

    Jimmy_Ma_0-1759307219832.png

     

    Thanks for the information.

     

    Jimmy