Skip to main content
Visitor II
February 6, 2019
Solved

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

  • February 6, 2019
  • 3 replies
  • 5456 views

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?

    This topic has been closed for replies.
    Best answer by Andreas Bolsch

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

    3 replies

    Explorer II
    February 6, 2019

    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.

    VTaraAuthor
    Visitor II
    February 6, 2019

    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.

    Explorer II
    February 6, 2019

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

    VTaraAuthor
    Visitor II
    February 6, 2019

    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.

    Super User
    July 31, 2024

    @VTara wrote:

    It seems I need to improve my knowledge in electrical details of MCU peripherals


    Indeed - and standard interfaces such as I2C and SPI.

    The MCU peripheral just implements the requirements of the standard.

     

    Graduate II
    July 31, 2024

    Hi

    I highly recommend the 'STM32F0 Arm Cortex M0' book which also covers this topic. Author i.a. Muhammad Ali Mazidi. It can be bought online.