Electronic – What happens on the STM32 when two pins are configured to have the same alternate function


Reading through the STM32F051 manual, it looks like it's possible to configure the same alternate function on two pins; for example, you could have multiple USART1_TX pins at the same time. Or for example the more problematic case of two USART_RX pins. The manual is silent on this case. Is this legal/safe? Is this useful?

Best Answer

On processors which use per-pin registers to select I/O functions, it is generally possible to route an output function to multiple pins without conflict; all pins will echo the same output. The effect of having multiple pins connected to an input is often unspecified; if e.g. a UART had I/O pins 3 and 4 connected to a UART, it might behave as though the UART was connected to an "AND" gate which took pins 3 and 4 as inputs, or it might behave as though it was connected to one pin and ignore the other, or it might connect both pins to the UART's input buffer through transistors that had a moderate amount of resistance, or it might draw extra current when pin 3 is high and 4 is low or vice versa, or it might do just about anything else imaginable. I don't recall having seen any particular guarantees that any of the STM32 family chips I looked at would favor any particular approach over any other.

A somewhat nicer design approach, used in some Microchip parts (perhaps some STM parts as well) is to have each I/O function include a multiplexer to select which pin it should accept input from, and have pin include a multiplexer to indicate the I/O function from which it should output data. Such a design makes it possible to have one pin feed multiple I/O functions, while simultaneously eliminating any ambiguities posed by conflicting configurations.