Merge pull request #5541 from DavePutz/issue_5477

Corrected number of serial bytes returned
This commit is contained in:
Scott Shawcroft 2021-11-03 16:53:15 -07:00 committed by GitHub
commit 0dfb7a9a2d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 8 additions and 1 deletions

View File

@ -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
@ -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.