STM32f429VGT UART7 alternate function - Page 1
Forum section: electronics / general

author: gremlin512
author_rank: Newbie
timestamp: August 28, 2024, 05:48:27 am
content: Noob here, is there a way to swap default uart pins, eg: i accidently made my PCBto have RX to PE8 & TX to PE7, where on stm32cube i only could assign RX to PE7 & TX to PE8. i heard there is this thing called alternate function would it work?

author: darkspr1te
author_rank: Frequent Contributor
timestamp: August 28, 2024, 06:18:48 am
content: Alternate function is to swap the various modes for a group of pins, e.g UART TX, MOSI Spi , Data i2c etc but they are all "outgoing signals" and RX would be on a different pin,You could use software UART in this case but you wont be able to swap the pin functions on STM32's RX will always be RX and cant be swapped for TX in a hardware scenariodarkspr1te

author: gremlin512
author_rank: Newbie
timestamp: August 28, 2024, 06:27:50 am
content: I see, you made a good point to use software serial, but why even if I use software serial, I can't utilize the RX pin?, it can act as both input and output.

author: darkspr1te
author_rank: Frequent Contributor
timestamp: August 28, 2024, 06:52:44 am
content: hardware uarts already have their paths set in silicon and when you switch to alternate mode it engages this pre-set UART state machine, thats 100% set in silicon, the software side engages another path which can act as in/out/high z and this is the one we use for software serial.Devices like the pi pico have a different system where the UART path is then connected to a matrix which can route to any pin, the STM does have this function.darkspr1te

author: Jeroen3
author_rank: Super Contributor
timestamp: August 28, 2024, 07:02:32 am
content: Yeah, sometimes chips have an option to swap rx/tx, the F429 is not one of them.But this would be a peripheral feature, not io multiplexer. (you'd get a short if you connect both)Eg: for the L486 is, "SWAP" is bit 15 in USART_CR2.

author: pcprogrammer
author_rank: Super Contributor
timestamp: August 28, 2024, 07:11:25 am
content: Quote from: gremlin512 on August 28, 2024, 05:48:27 amMy advice to every noob out there is to study datasheets first before jumping into designing a schematic and PCB.Go and read the datasheet and the reference manual and you would know that there is no way to use the UART with your connections.https://www.st.com/en/microcontrollers-microprocessors/stm32f429vg.htmlThe alternate functions are the options connected to a GPIO pin, and for PE7 they are TIM1_ETR, UART7_RX, FMC_D4 and event out. So no option to use it for UART7_TX.Another functionality of the alternate function setup is that a peripheral can be connected to different sets of GPIO pins.The setup in the F4 range of MCU differs from what is used in the F1 range. In the F4 range it is more flexible, but unfortunately for you not so flexible that you can swap RX and TX.When you have to live with the PCB you made, using a software UART is the only option. But this is slow and needs constant polling for the receiver, unless the pin can be used to trigger an interrupt on the EXTI peripheral. Then it is possible to detect a falling edge and start the polling based on that. Search the web for example code.I myself would bite the bullet and redesign the PCB.

author: hans
author_rank: Super Contributor
timestamp: August 28, 2024, 08:39:46 am
content: On this F4 part you cannot.I happen to know that on more modern STM32s, like the STM32U535, there is a "SWAP" bit in the UART CR2 register that can swap these pins. But that won't solve anything for you in this case.Swapping tx/rx is a classic mistake to make..Perhaps you can try patching the board? See if you can break the board connections and reverse the connections at an easy to solder place? At worst, you would have to solder directly on the STM32 pins, which is possible with a very steady hand, patience and tiny wire, but I can also imagine you don't want to do that.At worst you could choose to use only 1 direction of the UART, tie both STM32 pins together and break the offending other connection.

author: gremlin512
author_rank: Newbie
timestamp: August 29, 2024, 05:28:32 am
content: Thanks all, for the moment patched the PCB, directly hard wired to STM32 pins, Added the correction for the next PCB run. Thank you all for the insights. I'd definitely double check about these specific peripherals next time.