cancel
Showing results for 
Search instead for 
Did you mean: 

What state is the port pin in between GPIO MODER changes and GPIO AFR changes?

KRogo
Associate II

Consider: The pins are ultimately driving Power Mosfets, wherein the state of the outputs is of significant importance.

However, between the time when one changes the MODER register(s) for the appropriate pin(s) to AF and the time when one changes the AFR register(s), the pins are apparently in UNPREDICTABLE/UNCONTROLLABLE states!?

The answer seems to be to initialize the (alternate function) peripheral FIRST - putting it's 'outputs' into a known state, and THEN changing the AFR registers FIRST and then changing the MODER registers.

HOWEVER, ST documentation/code found indicates that MODER should be done BEFORE AFR ... WHY???

2 REPLIES 2
S.Ma
Principal

Maybe it seems either you get a glitch to the GPIO or a glitch on the peripheral incoming signals.

If your concern is on the output signals, after reset all the pins are input.

First, set the output register with the desired static level

Second, set the AF

Third, change MODER

Ideally MODER is changed in several steps, if needed, where a single bit is changed at a time in a controlled manner. (input => output => AF)

and... check on a scope probe if all looks fine. Now remain the question WHEN the peripheral should be reset and enabled vs GPIO's ....

KRogo
Associate II

I appreciate your response. I am understanding of your comments. I will reassert the issue:

The ST library stm32f0xx_gpio.c at GPIO_PinAFConfig (which sets the AFR register) says:

"The pin should already been configured in Alternate Function mode(AF) using GPIO_InitStruct->GPIO_Mode = GPIO_Mode_AF"

IF THIS is adhered to, FIRST the MODER register gets set to AF for that pin and SECOND the AFR register gets set to select the actual Alternate Function!

This MEANS: The moment you set the MODER to AF (as suggested by ST), the output pin is driven by an unknown (uninitialized; out-of-scope/pervue) peripheral. Are they suggesting I initialize/take control of ALL the relevant peripherals! Silly!!!

This makes NO sense. MAIN QUESTION is: WHY ARE THEY saying this? They should be saying the opposite order. ST should be answering this question!

i.e. WHY do they (ST) say I need to set MODER FIRST ???