cancel
Showing results for 
Search instead for 
Did you mean: 

How a GPIO pin binds to a PWM channel

Jimmy_Ma
Associate II

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

 

1 ACCEPTED SOLUTION

Accepted Solutions
waclawek.jan
Super User

@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

 

View solution in original post

3 REPLIES 3
mƎALLEm
ST Employee

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.

 

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.
waclawek.jan
Super User

@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

 

@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