Skip to content

Commit 3f2ee46

Browse files
committed
ports/rp2: Make split-heap optional.
My tests found issues when PSRAM is combined with the existing RAM in a split-heap configuration. Since this option is not enabled by default on RP2 I have changed it to be optional. PSRAM will be used exclusively if MICROPY_GC_SPLIT_HEAP == 0, it will be added to RAM if MICROPY_GC_SPLIT_HEAP == 1, and the system will fall back to RAM only if it's not detected. Signed-off-by: Phil Howard <[email protected]>
1 parent 083fa98 commit 3f2ee46

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

ports/rp2/main.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,12 +119,20 @@ int main(int argc, char **argv) {
119119
// Initialise stack extents and GC heap.
120120
mp_cstack_init_with_top(&__StackTop, &__StackTop - &__StackBottom);
121121

122-
gc_init(&__GcHeapStart, &__GcHeapEnd);
123122
#if defined(MICROPY_HW_PSRAM_CS_PIN) && MICROPY_HW_ENABLE_PSRAM
124123
size_t psram_size = psram_init(MICROPY_HW_PSRAM_CS_PIN);
125124
if (psram_size) {
125+
#if MICROPY_GC_SPLIT_HEAP
126+
gc_init(&__GcHeapStart, &__GcHeapEnd);
126127
gc_add((void *)PSRAM_LOCATION, (void *)(PSRAM_LOCATION + psram_size));
128+
#else
129+
gc_init((void *)PSRAM_LOCATION, (void *)(PSRAM_LOCATION + psram_size));
130+
#endif
131+
} else {
132+
gc_init(&__GcHeapStart, &__GcHeapEnd);
127133
}
134+
#else
135+
gc_init(&__GcHeapStart, &__GcHeapEnd);
128136
#endif
129137

130138
#if MICROPY_PY_LWIP

ports/rp2/mpconfigport.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,8 @@
7373

7474
// Memory allocation policies
7575
#define MICROPY_GC_STACK_ENTRY_TYPE uint16_t
76-
#ifdef MICROPY_HW_ENABLE_PSRAM
77-
#define MICROPY_GC_SPLIT_HEAP (1)
76+
#ifndef MICROPY_GC_SPLIT_HEAP
77+
#define MICROPY_GC_SPLIT_HEAP (0) // whether PSRAM is added to or replaces the heap
7878
#endif
7979
#define MICROPY_ALLOC_PATH_MAX (128)
8080
#define MICROPY_QSTR_BYTES_IN_HASH (1)

0 commit comments

Comments
 (0)