Skip to main content
SNara.6
Associate
July 5, 2022
Question

Alternate Function 0 in STM32

  • July 5, 2022
  • 5 replies
  • 1916 views

In my STM32, if I have set the GPIO_MODER as "Alternate function" and did not set any values in the GPIO_AFRL and GPIO_AFHL, I guess it will take the defaukt value of AF0. What is AF0 used for ?

This topic has been closed for replies.

5 replies

Andrew Neil
Super User
July 5, 2022

"What is AF0 used for ?"

The datasheet will tell you that; eg,

0693W00000QKRrQQAX.png

A complex system that works is invariably found to have evolved from a simple system that worked.A complex system designed from scratch never works and cannot be patched up to make it work.
SNara.6
SNara.6Author
Associate
July 5, 2022

Thanks for the prompt response. I am trying to debug a failure scenario. PA5 is what is the GPIO pin used ? As per the reference manual, AF0 for this pin does not have any function. obviously, this is a misconfiguration ? My specific question is that if there is such a configuratuion, what will this GPIO pin output ? Will it be random ? or will it default to 1 or 0 ?

Andrew Neil
Super User
July 5, 2022

You haven't said what part you're using.

A complex system that works is invariably found to have evolved from a simple system that worked.A complex system designed from scratch never works and cannot be patched up to make it work.
SNara.6
SNara.6Author
Associate
July 6, 2022

STM32L151VE

waclawek.jan
Super User
July 5, 2022

Which STM32?

> I guess it will take the default value of AF0

You don't need to guess, the GPIO_AFR registers description in RM tells you exactly what the default values are.

> My specific question is that if there is such a configuratuion

> [for given pinm, MODER set to AF, AFR set to AF0, and there's no function assigned to AF0 in the datasheet],

> what will this GPIO pin output ? Will it be random ? or will it default to 1 or 0 ?

It is unspecified, i.e. the datasheet/reference manual won't tell you what will it do.

However, it is not likely to be entirely random. I have made that configuration mistake in the past, and my experience was, that the pin took the function of other AF defined for that pin. As pins set to AF in MODER are controlled by the assigned peripheral, this means, that the pin could behave as input or as output, set to either level or toggling (in my case, I was expecting that the pin will be set as input but given incorrect AF, it was set to ouput and . This of course means nothing, your chip may behave entirely differently.

JW