OysterShucker
OysterShucker

Reputation: 5531

Is GC Broken on RPi Pico

I am using the latest stable release of micropython and below is my entire program.

import gc
gc.collect()
print('free:{}, alloc:{}'.format(gc.mem_free(), gc.mem_alloc()))
#free:187488, alloc:4576

Where did 64k of my RAM go? I know it isn't a hardware issue. I plugged in a brand new Pico that doesn't even have headers soldered on it, and got the exact same results. Am I missing something?

EDIT:

I found the below in ports/rp2/main.c. Is there some reason why it's not 256?

static char gc_heap[192 * 1024];

Upvotes: 1

Views: 898

Answers (1)

OysterShucker
OysterShucker

Reputation: 5531

It appears that 64kb of RAM are automatically allocated to fit the firmware.elf. So, not only do you not actually get 264k of RAM (due to Hypervisor using 8k), but you don't get 256k of RAM either. Changing the edit in my question to:

static char gc_heap[256 * 1024];

leads to these messages:

firmware.elf section '.bss' will not fit in region 'RAM' 
region 'RAM' overflowed by 40848 bytes

Conclusion: There are only 192kb of usable RAM on a Raspberry Pi Pico that utilizes micropython.

Upvotes: 3

Related Questions