summaryrefslogtreecommitdiff
path: root/ports
diff options
context:
space:
mode:
authorJeff Epler <jepler@unpythonic.net>2018-08-01 20:21:20 -0500
committerJeff Epler <jepler@gmail.com>2018-08-08 19:21:57 -0500
commitb0e33f6a116ac75c6a26216224182529db78e0a3 (patch)
tree8abe6541ce21ee97a806adc4f593ba58f9cabcdd /ports
parente1b4e9b7c7cdd7a022a5ab113b68c8fa6be2c74d (diff)
atmel-samd: UART: allocate rx buffer in long-lived region
This is not strictly needed in order for #1056 to be resolved, because the "make long-lived" machinery is unaware of this pointer. However, as UARTs are assumed to be long-lived, this change is beneficial because it moves the long-lived buffer into the upper memory area with other long-lived objects, instead of remaining in the low heap.
Diffstat (limited to 'ports')
-rw-r--r--ports/atmel-samd/common-hal/busio/UART.c8
1 files changed, 7 insertions, 1 deletions
diff --git a/ports/atmel-samd/common-hal/busio/UART.c b/ports/atmel-samd/common-hal/busio/UART.c
index bcdeae7b5..20e662ec6 100644
--- a/ports/atmel-samd/common-hal/busio/UART.c
+++ b/ports/atmel-samd/common-hal/busio/UART.c
@@ -132,7 +132,13 @@ void common_hal_busio_uart_construct(busio_uart_obj_t *self,
if (rx && receiver_buffer_size > 0) {
self->buffer_length = receiver_buffer_size;
- self->buffer = (uint8_t *) gc_alloc(self->buffer_length * sizeof(uint8_t), false, false);
+ // Initially allocate the UART's buffer in the long-lived part of the
+ // heap. UARTs are generally long-lived objects, but the "make long-
+ // lived" machinery is incapable of moving internal pointers like
+ // self->buffer, so do it manually. (However, as long as internal
+ // pointers like this are NOT moved, allocating the buffer
+ // in the long-lived pool is not strictly necessary)
+ self->buffer = (uint8_t *) gc_alloc(self->buffer_length * sizeof(uint8_t), false, true);
if (self->buffer == NULL) {
common_hal_busio_uart_deinit(self);
mp_raise_msg(&mp_type_MemoryError, "Failed to allocate RX buffer");