From 32fbb18fa808904d2d08876096738df9d725fa2a Mon Sep 17 00:00:00 2001 From: Andrew Leech Date: Wed, 29 May 2024 11:48:19 +1000 Subject: [PATCH] nrf/uart: Handle sending (string) data stored in flash. Signed-off-by: Andrew Leech --- ports/nrf/modules/machine/uart.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/ports/nrf/modules/machine/uart.c b/ports/nrf/modules/machine/uart.c index de26fa1b12787..1ba801867d5a7 100644 --- a/ports/nrf/modules/machine/uart.c +++ b/ports/nrf/modules/machine/uart.c @@ -29,6 +29,7 @@ // This file is never compiled standalone, it's included directly from // extmod/machine_uart.c via MICROPY_PY_MACHINE_UART_INCLUDEFILE. +#include #include "py/mperrno.h" #include "py/mphal.h" #include "py/ringbuf.h" @@ -319,8 +320,17 @@ static mp_uint_t mp_machine_uart_read(mp_obj_t self_in, void *buf_in, mp_uint_t static mp_uint_t mp_machine_uart_write(mp_obj_t self_in, const void *buf_in, mp_uint_t size, int *errcode) { machine_uart_obj_t *self = self_in; + uint8_t *buf = (uint8_t *)buf_in; + #if !NRFX_UART_ENABLED + if (!nrfx_is_in_ram(buf_in)) { + // EasyDMA requires that transfer buffers are placed in DataRAM, + // NRFX_ERROR_INVALID_ADDR if the are not. + buf = alloca(size); + memcpy((void *)buf, buf_in, size); + } + #endif - nrfx_err_t err = nrfx_uart_tx(self->p_uart, buf_in, size); + nrfx_err_t err = nrfx_uart_tx(self->p_uart, buf, size); if (err == NRFX_SUCCESS) { while (nrfx_uart_tx_in_progress(self->p_uart)) { MICROPY_EVENT_POLL_HOOK;