Commit bedab235 authored by Paul Sokolovsky's avatar Paul Sokolovsky

stmhal/uart: If char is not received within timeout, return EAGAIN error.

Instead of return 0, which means EOF. There's no good way to detect EOF on
continuously active bus like UART, and treat timeout as just temporary
unvailability of data. .read() method of UART object will return None in
this case (instead of 0, which again measn EOF). This is fully compliant
with unix port.
parent 83158e0e
...@@ -772,9 +772,9 @@ STATIC mp_uint_t pyb_uart_read(mp_obj_t self_in, void *buf_in, mp_uint_t size, i ...@@ -772,9 +772,9 @@ STATIC mp_uint_t pyb_uart_read(mp_obj_t self_in, void *buf_in, mp_uint_t size, i
// wait for first char to become available // wait for first char to become available
if (!uart_rx_wait(self, self->timeout)) { if (!uart_rx_wait(self, self->timeout)) {
// we can either return 0 to indicate EOF (then read() method returns b'') // return EAGAIN error to indicate non-blocking (then read() method returns None)
// or return EAGAIN error to indicate non-blocking (then read() method returns None) *errcode = EAGAIN;
return 0; return MP_STREAM_ERROR;
} }
// read the data // read the data
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment