I have an ARM STM32 where each GPIO pin can be configured as "input", "output", "analogue" or "alternate function". In "alternate function" mode, the ARM drives a lot of the logic for basic communication protocols, removing some of the grunt work for the programmer.

While I have been able to "read" the value of input and output GPIO pins using the standard library functions GPIO_ReadInputDataBit and GPIO_ReadOutputDataBit, I cannot seem to be able to read the value of alternate function pins without using a scope.

Is there a way to query the ARM about the value of its alternate function pins?


1 Answer 1


Apparently not, and I haven't seen a microcontroller that could. When you assign the alternate function to the pin the signal is rerouted to that function's interface, away from the GPIO register. If you assign for instance the I2C function to a pair of pins the microcontroller will say that what happens at the pins is none of your business; you'll have to pass at the I2C controller.

It's obvious that the pin can't be used for output, because of the conflicts it would cause, but while the use as input is more harmless it seems to be pointless, since the I2C controller will give you everything you need.

Debugging is a possible purpose, but that's not the function of the microcontroller, that's what we have scopes and logic analyzers for.

  • 6
    \$\begingroup\$ This is not true for the STM32F4 for inputs. From the reference manual RM0090 (Rev18) section 8.3.11 Alternate function configuration: "When the I/O port is programmed as alternate function: ... The Schmitt trigger input is activated ... The data present on the I/O pin are sampled into the input data register every AHB1 clock cycle ... A read access to the input data register gets the I/O state" \$\endgroup\$
    – Batuu
    Apr 23, 2019 at 13:08
  • 1
    \$\begingroup\$ STM32G4 series also supports peeking at input state when alternate function is enabled (see RM0440 section 9.3.11). This is convenient when interfacing to components (e.g. AD4111) that use an SPI-compatible interface wherein the MISO pin is reused as a signal/flag (DOUT/nRDY) between transactions. "Figure 29. Alternate function configuration" on that same page (359/2127 in rev 6) shows how the (GP) output data is ignored but input goes to peripheral and data register. \$\endgroup\$
    – jacobq
    Nov 16, 2021 at 3:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.