Corrected number of serial bytes returned

This commit is contained in:
root 2021-11-03 16:29:05 -05:00
parent d2febfaf20
commit 1e3215f4ee
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 we timed out, stop the transfer
if (self->rx_ongoing) { if (self->rx_ongoing) {
uint32_t recvd = 0;
LPUART_TransferGetReceiveCount(self->uart, &self->handle, &recvd);
LPUART_TransferAbortReceive(self->uart, &self->handle); LPUART_TransferAbortReceive(self->uart, &self->handle);
return recvd;
} }
// No data left, we got it all // 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 // 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.) // 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. // Write characters.