Loading...
 
Skip to main content

System Workbench for STM32


Locate Heap in SDRAM

Tunisia

We can also do that without big modifcations in linker script 😀

by defining the heap start/end in linker miscellaneous flags, ie :

Copy to clipboard
-Wl,--defsym=__heap_start=0xD0000000,--defsym=__heap_limit=0xD0800000

Note: you have to change these values with yours

and removing heap informations from linker (not necessary but good for your linker lisibility)

1- remove this line :
_Min_Heap_Size = 0; /* required amount of heap */
2- and replace this

Copy to clipboard
/* User_heap_stack section, used to check that there is enough RAM left */ ._user_heap_stack : { . = ALIGN(8); PROVIDE ( end = . ); PROVIDE ( _end = . ); . = . + _Min_Heap_Size; . = . + _Min_Stack_Size; . = ALIGN(8); } >RAM

with the following

Copy to clipboard
/* User_stack section, used to check that there is enough RAM left */ ._user_stack : { . = ALIGN(8); PROVIDE ( end = . ); PROVIDE ( _end = . ); . = . + _Min_Stack_Size; . = ALIGN(8); } >RAM



Edit: I forgot syscalls modifications 😁

You have to add syscalls.c to project (you can borrow it from another SystemWorkbench project)
then replace _sbrk function by the following

Copy to clipboard
caddr_t _sbrk(int incr) { extern char __heap_start asm("__heap_start"); /* Defined by the linker. */ extern char __heap_limit asm("__heap_limit"); /* Defined by the linker. */ static char *heap_end; static char *heap_limit = &__heap_limit; char *prev_heap_end; if (heap_end == 0) heap_end = &__heap_start; prev_heap_end = heap_end; if (heap_end + incr > heap_limit) { errno = ENOMEM; // not enough memory return (caddr_t) -1; } heap_end += incr; return (caddr_t) prev_heap_end; }