Skip to content

Commit

Permalink
Merge pull request #5541 from DavePutz/issue_5477
Browse files Browse the repository at this point in the history
Corrected number of serial bytes returned
  • Loading branch information
tannewt authored Nov 3, 2021
2 parents 38c3816 + 1e3215f commit 0dfb7a9
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion ports/mimxrt10xx/common-hal/busio/UART.c
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,10 @@ size_t common_hal_busio_uart_read(busio_uart_obj_t *self, uint8_t *data, size_t

// if we timed out, stop the transfer
if (self->rx_ongoing) {
uint32_t recvd = 0;
LPUART_TransferGetReceiveCount(self->uart, &self->handle, &recvd);
LPUART_TransferAbortReceive(self->uart, &self->handle);
return recvd;
}

// No data left, we got it all
Expand All @@ -355,7 +358,11 @@ size_t common_hal_busio_uart_read(busio_uart_obj_t *self, uint8_t *data, size_t

// The only place we can reliably tell how many bytes have been received is from the current
// wp in the handle (because the abort nukes rxDataSize, and reading it before abort is a race.)
return self->handle.rxData - data;
if (self->handle.rxData > data) {
return self->handle.rxData - data;
} else {
return len;
}
}

// Write characters.
Expand Down

0 comments on commit 0dfb7a9

Please sign in to comment.