Skip to content

Commit 4cc5ad9

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 af4ac7b commit 4cc5ad9

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

125-
gc_init(&__GcHeapStart, &__GcHeapEnd);
126125
#if defined(MICROPY_HW_PSRAM_CS_PIN) && MICROPY_HW_ENABLE_PSRAM
127126
size_t psram_size = psram_init(MICROPY_HW_PSRAM_CS_PIN);
128127
if (psram_size) {
128+
#if MICROPY_GC_SPLIT_HEAP
129+
gc_init(&__GcHeapStart, &__GcHeapEnd);
129130
gc_add((void *)PSRAM_LOCATION, (void *)(PSRAM_LOCATION + psram_size));
131+
#else
132+
gc_init((void *)PSRAM_LOCATION, (void *)(PSRAM_LOCATION + psram_size));
133+
#endif
134+
} else {
135+
gc_init(&__GcHeapStart, &__GcHeapEnd);
130136
}
137+
#else
138+
gc_init(&__GcHeapStart, &__GcHeapEnd);
131139
#endif
132140

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