Skip to content

RP2040 and ESP32S2: Return correct count from UART.write() #4645

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 3 commits into from
Apr 23, 2021
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,7 @@ jobs:
id: idf-cache
with:
path: ${{ github.workspace }}/.idf_tools
key: ${{ runner.os }}-idf-tools-${{ hashFiles('.git/modules/ports/esp32s2/esp-idf/HEAD') }}-20210304
key: ${{ runner.os }}-idf-tools-${{ hashFiles('.git/modules/ports/esp32s2/esp-idf/HEAD') }}-20210422
- name: Clone IDF submodules
run: |
(cd $IDF_PATH && git submodule update --init)
Expand Down
7 changes: 4 additions & 3 deletions ports/esp32s2/common-hal/busio/UART.c
Original file line number Diff line number Diff line change
Expand Up @@ -291,13 +291,14 @@ size_t common_hal_busio_uart_write(busio_uart_obj_t *self, const uint8_t *data,
mp_raise_ValueError(translate("No TX pin"));
}

while (len > 0) {
int count = uart_tx_chars(self->uart_num, (const char *)data, len);
size_t left_to_write = len;
while (left_to_write > 0) {
int count = uart_tx_chars(self->uart_num, (const char *)data, left_to_write);
if (count < 0) {
*errcode = MP_EAGAIN;
return MP_STREAM_ERROR;
}
len -= count;
left_to_write -= count;
data += count;
RUN_BACKGROUND_TASKS;
}
Expand Down
7 changes: 4 additions & 3 deletions ports/raspberrypi/common-hal/busio/UART.c
Original file line number Diff line number Diff line change
Expand Up @@ -191,12 +191,13 @@ size_t common_hal_busio_uart_write(busio_uart_obj_t *self, const uint8_t *data,
mp_raise_ValueError(translate("No TX pin"));
}

while (len > 0) {
while (uart_is_writable(self->uart) && len > 0) {
size_t left_to_write = len;
while (left_to_write > 0) {
while (uart_is_writable(self->uart) && left_to_write > 0) {
// Write and advance.
uart_get_hw(self->uart)->dr = *data++;
// Decrease how many chars left to write.
len--;
left_to_write--;
}
RUN_BACKGROUND_TASKS;
}
Expand Down