8000 stmhal/uart: If char is not received within timeout, return EAGAIN er… · micropython/micropython@bedab23 · GitHub
[go: up one dir, main page]

Skip to content

Commit bedab23

Browse files
author
Paul Sokolovsky
committed
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.
1 parent 83158e0 commit bedab23

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

stmhal/uart.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -772,9 +772,9 @@ STATIC mp_uint_t pyb_uart_read(mp_obj_t self_in, void *buf_in, mp_uint_t size, i
772772

773773
// wait for first char to become available
774774
if (!uart_rx_wait(self, self->timeout)) {
775-
// we can either return 0 to indicate EOF (then read() method returns b'')
776-
// or return EAGAIN error to indicate non-blocking (then read() method returns None)
777-
return 0;
775+
// return EAGAIN error to indicate non-blocking (then read() method returns None)
776+
*errcode = EAGAIN;
777+
return MP_STREAM_ERROR;
778778
}
779779

780780
// read the data

0 commit comments

Comments
 (0)
0