Skip to content

Corrected number of serial bytes returned #5541

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 3, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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