cancel
Showing results for 
Search instead for 
Did you mean: 

Changing the pin connections on the STM32F407VET6

No_Name
Associate III

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.

1 ACCEPTED SOLUTION

Accepted Solutions

@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 ...

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.

View solution in original post

7 REPLIES 7
Andrew Neil
Super User

@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 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.

Okay, I understand. That means AF (alternative function) has been determined from the datasheet and is not free. So, if I want to use two different protocols (switching) on the same pin, I have to use PB10 and PB11.

 

No_Name_0-1765972457457.png

 

waclawek.jan
Super User

I2C master can be easily bit-banged, though.

JW

> That means AF (alternative function) has been determined from the datasheet and is not free.

Alternate Functions (AF) describe the hardware implementation in regard to this pin.
And only one can be active at a time.

While I2C can be bit-banged (as mentioned), it will consume quite a bit of core performance with medium or high transfer loads.


@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 ...

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.

Okay, I understand now. Thank you.