cancel
Showing results for 
Search instead for 
Did you mean: 

How to configure Push-Pull/Open drain and Pull up/down for GPIO configured as AF?

VTara
Associate II

I can not find any instruction in documents about gpio configuration in alternate function mode. For example I want to configure SPI GPIO. Examples found in the internet have different configuration. Is it unimportant to configure push pull and pull up/down parameters?

1 ACCEPTED SOLUTION

Accepted Solutions
Andreas Bolsch
Lead II

You can't "get" such information magically from somewhere but you have to think about *your* requirements: E. g. SPI clock speed determines the slew rate setting, I2C usually requires open-drain, for an input connected to a simple switch you would use a pull-up if the switch's is connected to GND etc. (however, in a noisy environment with a remote switch the internal pull-up might be to weak and some sort of protection necessary).

View solution in original post

4 REPLIES 4
Andreas Bolsch
Lead II

The alternate function settings have litte impact on the port configuration: output state is taken from the "alternate" peripheral rather than from ODR. The output configuration (pp vs. od, pull-up/-down) is still handled in the very same was as for normal GPIO, i e. via OTYPER, OSPEEDR, PUPDR., see 6.3.2 im RM:

"Peripheral alternate function:

– Connect the I/O to the desired AFx in one of the GPIOx_AFRL or GPIOx_AFRH register.

– Select the type, pull-up/pull-down and output speed via the GPIOx_OTYPER,

GPIOx_PUPDR and GPIOx_OSPEEDER registers, respectively.

– Configure the desired I/O as an alternate function in the GPIOx_MODER register."

and the following paragraph.

The only exception are "special" pins, e. g. oscillator, where the activation overrides GPIO settings.

G0 family is not different to others in this respect.

OK, I understand that I need to configure GPIOx_MODER, GPIOx_OTYPER, GPIOx_PUPDR and GPIOx_OSPEEDER. But which values should be programmed? Where can I get such information? And this question is not about G0 family only or SPI GPIO only. I really do not understand where to get particular values for programming GPIO registers for GPIO in alternate function mode.

Andreas Bolsch
Lead II

You can't "get" such information magically from somewhere but you have to think about *your* requirements: E. g. SPI clock speed determines the slew rate setting, I2C usually requires open-drain, for an input connected to a simple switch you would use a pull-up if the switch's is connected to GND etc. (however, in a noisy environment with a remote switch the internal pull-up might be to weak and some sort of protection necessary).

Thank you. It seems I need to improve my knowledge in electrical details of MCU peripherals 🙂 Thank you. The problem is solved.

In fact, I saw some recomendations for f103 family. That's why I asked this question.