• cpottle9's avatar
    rp2: Allocate GC heap from unused RAM. · c80e7c14
    cpottle9 authored
    Borrowing an idea from the mimxrt port (also stm32 port): in the loader
    input file memmap_mp.ld calculate __GcHeapStart and __GcHeapEnd as the
    unused RAM.  Then in main.c use these addresses as arguments to gc_init().
    
    The benefits of this change are:
    
    1) When libraries are added or removed in the future changing BSS usage,
       main.c's sizing of the GC heap does not need to be changed.
    
    2) Currently these changes make the GC area about 30 KBytes larger, eg on
       PICO_W the GC heap increases from 166016 to 192448 bytes.  Without that
       change this RAM would never get used.
    
    3) If someone wants to disable one or more SRAM blocks on the RP2040 to
       reduce power consumption it will be easy: just change the MEMORY section
       in memmap_mp.ld.  For instance to not use SRAM2 and SRAM3 change it to:
    
            MEMORY
            {
                FLASH(rx) : ORIGIN = 0x10000000, LENGTH = 2048k
                RAM(rwx) : ORIGIN =  0x21000000, LENGTH = 128k
                SCRATCH_X(rwx) : ORIGIN = 0x20040000, LENGTH = 4k
                SCRATCH_Y(rwx) : ORIGIN = 0x20041000, LENGTH = 4k
            }
    
       Then to turn off clocks for SRAM2 and SRAM3 from MicroPython, set the
       appropriate bits in WAKE_EN0 and SLEEP_EN0.
    
    Tested by running the firmware.uf2 file on PICO_W and displaying
    micropython.mem_info().  Confirmed GC total size approximately matched the
    size calculated by the loader.
    Signed-off-by: default avatarcpottle9 <cpottle9@outlook.com>
    c80e7c14
memmap_mp.ld 7.21 KB