Shared UART on STM32F103x (or any)
Yes (if I understand your question correctly).
As you did not specify the part number, let's take the 48-pin STM32F103C8T6 found on the &quot;Blue Pill&quot; boards as an example.
USART2 and USART3 are hardwired to PA2-PA3 and PB10-PB11, but USART1 can be relocated from the default PA9-PA10 pair to PB6-PB7. (Actually USART2 and USART3 can be relocated as well, but to pins that don't exist on the 48 bit package.)
Remapping is controlled by the USART1_REMAP bits of the AFIO-&gt;MAPR register.

Bit 2 USART1_REMAP: USART1 remapping
This bit is set and cleared by software. It controls the mapping of USART1 TX and RX alternate functions on the GPIO ports.
0: No remap (TX/PA9, RX/PA10)
1: Remap (TX/PB6, RX/PB7)

Of course only one of the connections can be active at any given time, but the switchover can occur any time. The other device will be disconnected, it will not receive any data from the controller, and any data sent to the controller will be lost.
The tricky part is to properly finish the communication with one device before the switchover.

If you are just sending output to a port, then wait until the TC bit in USART1-&gt;SR is set. Waiting for TXE is not enough, as the UART can be still busy transmitting the last byte, which will be lost, or partially transmitted to the wrong device.

If hardware flow control is possible, you can connect a GPIO pin to the CTS input of the device. Set the pin to 1 to tell the device to stop transmitting, and wait for the time needed to finish sending a complete byte before switchover.

Otherwise the steps needed to shut down communication depends on the communication protocol. Checkwhether some kind of software flow control is available.



There is also a software UART implementation for ST. Although it's for the F4 series, I see no reason why it couln't be ported to F1.