From 1782ceab356d3c02f7d4a4319a6552654933da15 Mon Sep 17 00:00:00 2001 From: hathach Date: Mon, 24 Sep 2018 16:18:49 +0700 Subject: [PATCH] uarte malloc if buffer is not in SRAM --- ports/nrf/common-hal/busio/UART.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/ports/nrf/common-hal/busio/UART.c b/ports/nrf/common-hal/busio/UART.c index 7e6fddf2f8..5bb51bb74c 100644 --- a/ports/nrf/common-hal/busio/UART.c +++ b/ports/nrf/common-hal/busio/UART.c @@ -203,7 +203,14 @@ size_t common_hal_busio_uart_write(busio_uart_obj_t *self, const uint8_t *data, nrfx_uarte_tx_abort(&self->uarte); } - (*errcode) = nrfx_uarte_tx(&self->uarte, data, len); + // EasyDMA can only access SRAM + uint8_t * tx_buf = (uint8_t*) data; + if ( !nrfx_is_in_ram(data) ) { + tx_buf = (uint8_t *) gc_alloc(len, false, false); + memcpy(tx_buf, data, len); + } + + (*errcode) = nrfx_uarte_tx(&self->uarte, tx_buf, len); _VERIFY_ERR(*errcode); (*errcode) = 0; @@ -214,6 +221,10 @@ size_t common_hal_busio_uart_write(busio_uart_obj_t *self, const uint8_t *data, #endif } + if ( !nrfx_is_in_ram(data) ) { + gc_free(tx_buf); + } + return len; #endif }