Skip to content

Commit 9d8545e

Browse files
authored
Merge pull request #4645 from dhalbert/rp2040-uart-write
RP2040 and ESP32S2: Return correct count from UART.write()
2 parents 7157693 + c931c84 commit 9d8545e

File tree

3 files changed

+9
-7
lines changed

3 files changed

+9
-7
lines changed

.github/workflows/build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -482,7 +482,7 @@ jobs:
482482
id: idf-cache
483483
with:
484484
path: ${{ github.workspace }}/.idf_tools
485-
key: ${{ runner.os }}-idf-tools-${{ hashFiles('.git/modules/ports/esp32s2/esp-idf/HEAD') }}-20210304
485+
key: ${{ runner.os }}-idf-tools-${{ hashFiles('.git/modules/ports/esp32s2/esp-idf/HEAD') }}-20210422
486486
- name: Clone IDF submodules
487487
run: |
488488
(cd $IDF_PATH && git submodule update --init)

ports/esp32s2/common-hal/busio/UART.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -291,13 +291,14 @@ size_t common_hal_busio_uart_write(busio_uart_obj_t *self, const uint8_t *data,
291291
mp_raise_ValueError(translate("No TX pin"));
292292
}
293293

294-
while (len > 0) {
295-
int count = uart_tx_chars(self->uart_num, (const char *)data, len);
294+
size_t left_to_write = len;
295+
while (left_to_write > 0) {
296+
int count = uart_tx_chars(self->uart_num, (const char *)data, left_to_write);
296297
if (count < 0) {
297298
*errcode = MP_EAGAIN;
298299
return MP_STREAM_ERROR;
299300
}
300-
len -= count;
301+
left_to_write -= count;
301302
data += count;
302303
RUN_BACKGROUND_TASKS;
303304
}

ports/raspberrypi/common-hal/busio/UART.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -191,12 +191,13 @@ size_t common_hal_busio_uart_write(busio_uart_obj_t *self, const uint8_t *data,
191191
mp_raise_ValueError(translate("No TX pin"));
192192
}
193193

194-
while (len > 0) {
195-
while (uart_is_writable(self->uart) && len > 0) {
194+
size_t left_to_write = len;
195+
while (left_to_write > 0) {
196+
while (uart_is_writable(self->uart) && left_to_write > 0) {
196197
// Write and advance.
197198
uart_get_hw(self->uart)->dr = *data++;
198199
// Decrease how many chars left to write.
199-
len--;
200+
left_to_write--;
200201
}
201202
RUN_BACKGROUND_TASKS;
202203
}

0 commit comments

Comments
 (0)