← index #16079Issue #16373
Off-topic · high · value 2.785
QUERY · ISSUE

UART with the same pin for both RX and TX doesn't work on ESP32 variants

openby arduino12opened 2024-10-25updated 2026-03-24
enhancementport-esp32

Port, board and/or hardware

esp32 port

MicroPython version

MicroPython v1.23.0 on 2024-06-02; LOLIN_C3_MINI with ESP32-C3FH4
MicroPython v1.23.0 on 2024-06-02; LOLIN_S2_MINI with ESP32-S2FN4R2
MicroPython v1.23.0-602.g403401490d on 2024-10-25; LOLIN S3 MINI with ESP32S3
MicroPython v1.23.0 on 2024-06-02; Generic ESP32S3 module with ESP32S3

Reproduction

from micropython import const
from machine import Pin, UART, mem32

PIN_NUM = const(2)
PIN_FUNC_REG = const(0x60004554 + 4 * PIN_NUM) # GPIO_FUNCx_OUT_SEL_CFG_REG 
UART_NUM = const(1)
UART_BAUDRATE = const(1000000)

pin = Pin(PIN_NUM)

# pass the same `pin` to `tx` and `rx` doesn't work!
uart = UART(UART_NUM, UART_BAUDRATE, tx=pin, rx=pin)
uart.write(b'test') # UART signal doesn't routed to `PIN_NUM `.
print(uart.read()) # nothing gets printed..

# pass only `tx` (to get the `UART_SIG` number)
uart = UART(UART_NUM, UART_BAUDRATE, tx=pin)
UART_SIG = mem32[PIN_FUNC_REG] # see "Peripheral Signals via GPIO Matrix" in datasheet

# now try again, this time overwrite `PIN_FUNC_REG` with previous value
uart = UART(UART_NUM, UART_BAUDRATE, tx=pin, rx=pin)
mem32[PIN_FUNC_REG] = UART_SIG # ESP32-C3 is 6, ESP32-S3 is 12...
uart.write(b'test')
print(uart.read()) # b'test' is printed!

Expected behaviour

I expected:

uart = UART(UART_NUM, UART_BAUDRATE, tx=pin, rx=pin)

to work- but is seems to overwrite the TX output configuration and only the RX pin is configured correctly.

My workaround is to re-write the TX output configuration after the UART initialization:

uart = UART(UART_NUM, UART_BAUDRATE, tx=pin, rx=pin)
mem32[PIN_FUNC_REG] = UART_SIG

I think the UART class needs to support this case of a single pin for both TX and RX.
I use it to control some single line smart servo motors with open-drain UART bus...

The ESP32 support this common UART configuration (like RS485),
it also support echo-cancellation that may also be a nice option for the UART class..

Observed behaviour

Tested the provided sample code on ESP32-S2, ESP32-S3, ESP32-C3 -
All have the same bug and the same suggested workaround fix.

Additional Information

No, I've provided everything above.

Code of Conduct

Yes, I agree

CANDIDATE · ISSUE

UART Ch 1 GPIO 4&5 on RP2040 Pico stopped working with 1.24 releases

closedby gobbyoopened 2024-12-07updated 2025-01-31
bug

Port, board and/or hardware

RP2040 Pico UART CH1 GPIO4&5

MicroPython version

The following have been tested and UART CH1 does not work on GPIO 4&5 (I didn't try other pins) on the RP2040 Pico:
v1.24.1 (2024-11-29) .uf2
v1.24.0 (2024-10-25) .uf2
v1.25.0-preview.81.g2c80d3699 (2024-12-06) .uf2

Reproduction

def testUART(channel, txpin, rxpin, payload="Hello from the Pico!"):
uart = UART(channel)
uart.init(channel, 9600, rx=Pin(rxpin), tx=Pin(txpin))
uart.write(payload.encode('utf-8'))
time.sleep(.2)
if uart.any() > 0:
b = bytearray(payload, 'utf-8')
size = uart.readinto(b)
if b != None:
s = b.decode('utf-8')
print("UART{0}: {1}(size={2})".format(channel, s, size))
uart.deinit()

def main():
testUART(0,0,1)
testUART(1,4,5)

Expected behaviour

Per the example code above, I expected the UART TX of "Hello from the Pico" text to be received. The code works for all releases prior to 1.24.

Observed behaviour

I didn't create a debug build to see the log output.

Additional Information

No, I've provided everything above.

Code of Conduct

Yes, I agree

Keyboard

j / / n
next pair
k / / p
previous pair
1 / / h
show query pane
2 / / l
show candidate pane
c
copy suggested comment
r
toggle reasoning
g i
go to index
?
show this help
esc
close overlays

press ? or esc to close

copied