Skip to content

Commit d1f4a99

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 30809fe commit d1f4a99

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
@@ -118,12 +118,20 @@ int main(int argc, char **argv) {
118118
// Initialise stack extents and GC heap.
119119
mp_cstack_init_with_top(&__StackTop, &__StackTop - &__StackBottom);
120120

121-
gc_init(&__GcHeapStart, &__GcHeapEnd);
122121
#if defined(MICROPY_HW_PSRAM_CS_PIN) && MICROPY_HW_ENABLE_PSRAM
123122
size_t psram_size = psram_init(MICROPY_HW_PSRAM_CS_PIN);
124123
if (psram_size) {
124+
#if MICROPY_GC_SPLIT_HEAP
125+
gc_init(&__GcHeapStart, &__GcHeapEnd);
125126
gc_add((void *)PSRAM_LOCATION, (void *)(PSRAM_LOCATION + psram_size));
127+
#else
128+
gc_init((void *)PSRAM_LOCATION, (void *)(PSRAM_LOCATION + psram_size));
129+
#endif
130+
} else {
131+
gc_init(&__GcHeapStart, &__GcHeapEnd);
126132
}
133+
#else
134+
gc_init(&__GcHeapStart, &__GcHeapEnd);
127135
#endif
128136

129137
#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)