|
46 | 46 | #include "nrfx_uarte.h"
|
47 | 47 | #endif
|
48 | 48 |
|
| 49 | +#if defined(NRF52832) |
| 50 | +// The nRF52832 cannot write more than 255 bytes at a time. |
| 51 | +#define UART_MAX_TX_CHUNK (255) |
| 52 | +#endif |
| 53 | + |
49 | 54 | typedef struct _machine_uart_buf_t {
|
50 | 55 | uint8_t tx_buf[1];
|
51 | 56 | uint8_t rx_buf[1];
|
@@ -456,17 +461,29 @@ static mp_uint_t mp_machine_uart_write(mp_obj_t self_in, const void *buf, mp_uin
|
456 | 461 | #endif
|
457 | 462 |
|
458 | 463 | machine_uart_obj_t *self = self_in;
|
459 |
| - nrfx_err_t err = nrfx_uart_tx(self->p_uart, buf, size); |
460 |
| - if (err == NRFX_SUCCESS) { |
| 464 | + |
| 465 | + // Send data out, in chunks if needed. |
| 466 | + mp_uint_t remaining = size; |
| 467 | + while (remaining) { |
| 468 | + #ifdef UART_MAX_TX_CHUNK |
| 469 | + mp_uint_t chunk = MIN(UART_MAX_TX_CHUNK, remaining); |
| 470 | + #else |
| 471 | + mp_uint_t chunk = remaining; |
| 472 | + #endif |
| 473 | + nrfx_err_t err = nrfx_uart_tx(self->p_uart, buf, chunk); |
| 474 | + if (err != NRFX_SUCCESS) { |
| 475 | + *errcode = mp_hal_status_to_errno_table[err]; |
| 476 | + return MP_STREAM_ERROR; |
| 477 | + } |
461 | 478 | while (nrfx_uart_tx_in_progress(self->p_uart)) {
|
462 | 479 | MICROPY_EVENT_POLL_HOOK;
|
463 | 480 | }
|
464 |
| - // return number of bytes written |
465 |
| - return size; |
466 |
| - } else { |
467 |
| - *errcode = mp_hal_status_to_errno_table[err]; |
468 |
| - return MP_STREAM_ERROR; |
| 481 | + buf += chunk; |
| 482 | + remaining -= chunk; |
469 | 483 | }
|
| 484 | + |
| 485 | + // return number of bytes written |
| 486 | + return size; |
470 | 487 | }
|
471 | 488 |
|
472 | 489 | static mp_uint_t mp_machine_uart_ioctl(mp_obj_t self_in, mp_uint_t request, uintptr_t arg, int *errcode) {
|
|
0 commit comments