8000 atmel-samd: UART: allocate rx buffer in long-lived region · sparkfun/circuitpython@b0e33f6 · GitHub
[go: up one dir, main page]

Skip to content

Commit b0e33f6

Browse files
committed
atmel-samd: UART: allocate rx buffer in long-lived region
This is not strictly needed in order for adafruit#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.
1 parent e1b4e9b commit b0e33f6

File tree

1 file changed

+7
-1
lines changed
  • ports/atmel-samd/common-hal/busio

1 file changed

+7
-1
lines changed

ports/atmel-samd/common-hal/busio/UART.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,13 @@ void common_hal_busio_uart_construct(busio_uart_obj_t *self,
132132

133133
if (rx && receiver_buffer_size > 0) {
134134
self->buffer_length = receiver_buffer_size;
135-
self->buffer = (uint8_t *) gc_alloc(self->buffer_length * sizeof(uint8_t), false, false);
135+
// Initially allocate the UART's buffer in the long-lived part of the
136+
// heap. UARTs are generally long-lived objects, but the "make long-
137+
// lived" machinery is incapable of moving internal pointers like
138+
// self->buffer, so do it manually. (However, as long as internal
139+
// pointers like this are NOT moved, allocating the buffer
140+
// in the long-lived pool is not strictly necessary)
141+
self->buffer = (uint8_t *) gc_alloc(self->buffer_length * sizeof(uint8_t), false, true);
136142
if (self->buffer == NULL) {
137143
common_hal_busio_uart_deinit(self);
138144
mp_raise_msg(&mp_type_MemoryError, "Failed to allocate RX buffer");

0 commit comments

Comments
 (0)
0