RP2 UART timeout is incorrect
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.
rp2: Add timeout and invert to the machine.uart class
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.