stm32wl: reserve 2KB of stack via linker script to match NRF52, change sbrkHeadroom to use the start of the reserved stack region instead of the current stack pointer

The linker script was created by merging variants/STM32WLxx/WL54JCI_WL55JCI_WLE4J(8-B-C)I_WLE5J(8-B-C)I/ldscript.ld and system/ldscript.ld from stm32duino/Arduino_Core_STM32.
This commit is contained in:
Chloe Bethel
2026-04-16 13:57:21 +01:00
committed by Chloe Bethel
co-authored by Chloe Bethel
parent 0ee5777c15
commit 31418ca821
3 changed files with 217 additions and 4 deletions
+10 -4
View File
@@ -14,16 +14,22 @@
#include <malloc.h>
#include <unistd.h> // sbrk
#ifdef ARCH_STM32WL
// Returns the uncommitted sbrk headroom: addressable space between the current heap
// break and the stack pointer that has not yet been committed to the arena.
// Currently used on: ARCH_STM32WL
static uint32_t sbrkHeadroom()
{
uint32_t sp;
__asm volatile("mov %0, sp" : "=r"(sp));
// defined in STM32 linker script
extern char _estack;
extern char _Min_Stack_Size;
uint32_t max_sp = (uint32_t)(&_estack - &_Min_Stack_Size);
uint32_t heap_end = (uint32_t)sbrk(0);
return (sp > heap_end) ? (sp - heap_end) : 0;
return (max_sp > heap_end) ? (max_sp - heap_end) : 0;
}
#else
#error Unsupported architecture!
#endif
#endif
MemGet memGet;