diff --git a/ports/stm/boards/common_default.ld b/ports/stm/boards/common_default.ld index 62a6d63d11c..cdbe7d59a72 100644 --- a/ports/stm/boards/common_default.ld +++ b/ports/stm/boards/common_default.ld @@ -87,7 +87,9 @@ SECTIONS . = . + _minimum_heap_size; . = ALIGN(4); } >RAM - _ld_heap_end = ORIGIN(RAM) + LENGTH(RAM); + /* The stack sits at the top of RAM, so end the heap below it. The extra 1K matches + CIRCUITPY_EXCEPTION_STACK_SIZE, which port_stack_get_limit() counts as stack too. */ + _ld_heap_end = ORIGIN(RAM) + LENGTH(RAM) - _ld_default_stack_size - 1K; /* this just checks there is enough RAM for the stack */ .stack : diff --git a/ports/stm/boards/common_nvm.ld b/ports/stm/boards/common_nvm.ld index f2a0456e000..b057d9480fa 100644 --- a/ports/stm/boards/common_nvm.ld +++ b/ports/stm/boards/common_nvm.ld @@ -97,7 +97,9 @@ SECTIONS . = . + _minimum_heap_size; . = ALIGN(4); } >RAM - _ld_heap_end = ORIGIN(RAM) + LENGTH(RAM); + /* The stack sits at the top of RAM, so end the heap below it. The extra 1K matches + CIRCUITPY_EXCEPTION_STACK_SIZE, which port_stack_get_limit() counts as stack too. */ + _ld_heap_end = ORIGIN(RAM) + LENGTH(RAM) - _ld_default_stack_size - 1K; /* this just checks there is enough RAM for the stack */ .stack :