← index #11678PR #6870
Related · high · value 0.791
QUERY · ISSUE

RP2 UART timeout is incorrect

openby peterhinchopened 2023-06-01updated 2023-06-01
bug

To repro link pins 0 and 1 and paste the following:

from machine import UART, Pin
uart = UART(0, 115200, rx=Pin(1, Pin.IN), tx=Pin(0, Pin.OUT), timeout=1000_000, timeout_char=1000_000)
uart.readline()

It times out after 15s rather than 16.6minutes.

Setting a long timeout is a hack to resolve https://github.com/micropython/micropython/issues/10867. In my opinion it should be possible to disable the timeout (set it to infinity). In uasyncio systems, uasyncio should provide any timeouts required by the application.

CANDIDATE · PULL REQUEST

rp2: Add timeout and invert to the machine.uart class

closedby robert-hhopened 2021-02-09updated 2021-04-15
port-rp2

This is a first attempt. It works, timeout and timeout_chars can be set and the object is properly printed, but there is an inherent problem in the way, machine_uart_read() and maybe machine_uart_write() is called. The problem is, when .e.g at uart.read() the numbers requested is larger than the ones in the FIFO. And that is different to e.g. the esp32 port.

Situation          ESP32    RP2
request == present  OK       OK
none requested      OK      Error
request > present   OK      Error

What happens is, that on the RP2, if machine_uart_read() returns less than the initially requested bytes, it will be called again with the remaining number, which will then run into a timeout. On ESP32, the caller is just happy with what it got and returns to the top level. When uart.read() is called without an argument, the size at the machine_uart_read() is 256.
So the stream algorithm behaves different. machine_uart_read() is called different in these two ports.

As a temporary fix, the function machine_uart_read() returns on timeout without an error and with the numbers of bytes read.

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