← index #6851PR #6870
Duplicate · high · value 2.840
QUERY · ISSUE

read() & readline() on rp2 port don't work/work as expected

openby uksconeopened 2021-02-05updated 2021-02-13
port-rp2

the UART on the rp2 port mostly works. read([num of bytes]) works mostly as expected although it seems to drop bytes occasionally and "hangs" if you try to read more bytes than currently available however read() with no number of bytes to read set and readline() just sit there indefinitely. I suspect it's to do with the fact that timeout isn't implemented

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