Skip to main content
Associate III
December 17, 2025
Solved

Changing the pin connections on the STM32F407VET6

  • December 17, 2025
  • 2 replies
  • 856 views

Hi.

I have Uart pins (Rx/Tx) PA3 and PA2 on STM32F407VET6. Can these pins be changed to I2C (SDA SCL) in the program?
Are the pins on STM32 that have been assigned a protocol (SPI/I2C/Uart) constant and cannot be changed or replaced?

Thank you.

Best answer by Andrew Neil

@No_Name wrote:

if I want to use two different protocols (switching) on the same pin, I have to use PB10 and PB11.


Yes, those pins will give you options for both USART3 (RX, TX) and I2C2 (SDA, SCL).

PB10 could be SPI2_SCK, but PB11 has no SPI functions - and you would need some other pins to make a full SPI connection.

There may also be other pin combinations available ...

 

Again, remember that the external hardware for I2C is usually different from UART - so you'd have to bear that in mind.

Also, you'd have to ensure that all connected devices are happy with the protocol changing.

 

As @waclawek.jan suggested, there's always bit-banging ...

 

PS:

For finding available combinations, it's probably easier to use Table 9:

AndrewNeil_0-1765973659861.png

Easier to identify which pins have I2C, SPI, and UART ...

2 replies

Andrew Neil
Super User
December 17, 2025

@No_Name wrote:

I have Uart pins (Rx/Tx) PA3 and PA2 on STM32F407VET6. Can these pins be changed to I2C (SDA SCL) in the program?.


The datasheet will tell you if that is physically possible on that chip.

If it is physically possible then, yes - the software can change it at runtime.

 

However, the external hardware requirements for UART and I2C are rather different - so you'd have to take that into account...

 


@No_Name wrote:

Are the pins on STM32 that have been assigned a protocol (SPI/I2C/Uart) constant and cannot be changed or replaced?


Of course not.

The code generated by by CubeMX is just writing to registers to configure the pin options; it's just standard C code - nothing special or magic - you can do exactly the same in your own code.

You can examine the source code that CubeMX generates to see what it's doing.

PS:

But, of course, CubeMX can only enable configurations that are physically possible on the chip itself;

If the chip itself does not have I2C support on a pin, then CubeMX cannot magically "invent" that.

 

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.
Andrew Neil
Super User
December 17, 2025

@Andrew Neil wrote:


The datasheet will tell you if that is physically possible on that chip.


It's not:

AndrewNeil_0-1765969823952.png

https://www.st.com/resource/en/datasheet/stm32f407ve.pdf#page=50

via: https://www.st.com/en/microcontrollers-microprocessors/stm32f407ve.html#documentation

There is no I2C option on either PA2 or PA3

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.
waclawek.jan
Super User
December 17, 2025

I2C master can be easily bit-banged, though.

JW