Commit fe4ac49d authored by Damien George's avatar Damien George

rp2/memmap_mp.ld: Allow a board to reserve memory for the C heap.

Since c80e7c14 changed the GC heap to use
all unused RAM, there is no longer any RAM available for the traditional C
heap (which is not used by default in MicroPython but may be used by C
extensions).  This commit adds a provision for a board to reserve RAM for
the C heap, by defining MICROPY_C_HEAP_SIZE.
Signed-off-by: default avatarDamien George <damien@micropython.org>
parent 7ea06a3e
cmake_minimum_required(VERSION 3.12)
cmake_minimum_required(VERSION 3.13)
# Set build type to reduce firmware size
if(NOT CMAKE_BUILD_TYPE)
......@@ -45,6 +45,12 @@ if(NOT PICO_BOARD)
string(TOLOWER ${MICROPY_BOARD} PICO_BOARD)
endif()
# Set the amount of C heap, if it's not already set.
# If a board uses malloc then it must set this to at least 4096.
if(NOT MICROPY_C_HEAP_SIZE)
set(MICROPY_C_HEAP_SIZE 0)
endif()
# Enable extmod components that will be configured by extmod.cmake.
# A board may also have enabled additional components.
set(MICROPY_SSL_MBEDTLS ON)
......@@ -365,6 +371,10 @@ target_compile_options(${MICROPY_TARGET} PRIVATE
-Werror
)
target_link_options(${MICROPY_TARGET} PRIVATE
-Wl,--defsym=__micropy_c_heap_size__=${MICROPY_C_HEAP_SIZE}
)
set_source_files_properties(
${PICO_SDK_PATH}/src/rp2_common/pico_double/double_math.c
${PICO_SDK_PATH}/src/rp2_common/pico_float/float_math.c
......
......@@ -243,19 +243,19 @@ SECTIONS
} > FLASH
/* stack limit is poorly named, but historically is maximum heap ptr */
__StackLimit = ORIGIN(RAM) + LENGTH(RAM);
__StackLimit = __bss_end__ + __micropy_c_heap_size__;
/* Define start and end of GC heap */
__GcHeapStart = __StackLimit; /* after the C heap (sbrk limit) */
__GcHeapEnd = ORIGIN(RAM) + LENGTH(RAM);
/* Define memory for the C stack */
__StackOneTop = ORIGIN(SCRATCH_X) + LENGTH(SCRATCH_X);
__StackTop = ORIGIN(SCRATCH_Y) + LENGTH(SCRATCH_Y);
__StackOneBottom = __StackOneTop - SIZEOF(.stack1_dummy);
__StackBottom = __StackTop - SIZEOF(.stack_dummy);
/* Define start and end of GC heap */
__GcHeapStart = __bss_end__;
__GcHeapEnd = __StackLimit;
PROVIDE(__stack = __StackTop);
/* Check if data + heap + stack exceeds RAM limit */
ASSERT(__StackLimit >= __HeapLimit, "region RAM overflowed")
/* Check GC heap is at least 128 KB */
/* On a RP2040 using all SRAM this should always be the case. */
ASSERT((__GcHeapEnd - __GcHeapStart) > 128*1024, "GcHeap is too small")
......@@ -263,4 +263,3 @@ SECTIONS
ASSERT( __binary_info_header_end - __logical_binary_start <= 256, "Binary info must be in first 256 bytes of the binary")
/* todo assert on extra code */
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment