2019-02-05 11:41 PM
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?
Solved! Go to Solution.
2019-02-06 12:38 AM
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).
2019-02-06 12:09 AM
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.
2019-02-06 12:19 AM
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.
2019-02-06 12:38 AM
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).
2019-02-06 12:50 AM
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.
2024-07-31 10:14 AM
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.
2024-07-31 10:25 AM
@Andreas Bolsch wrote:I2C usually (sic?) requires open-drain
"usually" ?
:thinking_face:
Surely, I2C inherently requires open-drain?
2024-07-31 10:27 AM
@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.