Skip to content

Commit 2d3f1a1

Browse files
committed
When UART timeout of zero is given, make read() return data already available
1 parent 9b98ad7 commit 2d3f1a1

File tree

1 file changed

+5
-1
lines changed
  • ports/atmel-samd/common-hal/busio

1 file changed

+5
-1
lines changed

ports/atmel-samd/common-hal/busio/UART.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ size_t common_hal_busio_uart_read(busio_uart_obj_t *self, uint8_t *data, size_t
249249
uint64_t start_ticks = ticks_ms;
250250

251251
// Busy-wait until timeout or until we've read enough chars.
252-
while (ticks_ms - start_ticks < self->timeout_ms) {
252+
while (ticks_ms - start_ticks <= self->timeout_ms) {
253253
// Read as many chars as we can right now, up to len.
254254
size_t num_read = io_read(io, data, len);
255255

@@ -268,6 +268,10 @@ size_t common_hal_busio_uart_read(busio_uart_obj_t *self, uint8_t *data, size_t
268268
#ifdef MICROPY_VM_HOOK_LOOP
269269
MICROPY_VM_HOOK_LOOP
270270
#endif
271+
// If we are zero timeout, make sure we don't loop again (in the event
272+
// we read in under 1ms)
273+
if (self->timeout_ms == 0)
274+
break;
271275
}
272276

273277
if (total_read == 0) {

0 commit comments

Comments
 (0)