cancel
Showing results for 
Search instead for 
Did you mean: 

STM32H743: Moving the heap into SDRAM?

PMath.4
Senior III

Hi

I need a big heap for some json parsing. How do I re-locate the heap into SDRAM? Obviously this needs to happen fairly late in the initialisation sequence once the SDRAM has been set up and initialised.

Is there an equivalent of __set_MSP() ?

Thanks

1 ACCEPTED SOLUTION

Accepted Solutions
KnarfB
Principal III

For gcc+newlib: Adapt the implementation of void *_sbrk(ptrdiff_t incr) in sysmem.c. _sbrk is called twice for the first malloc. The first call with param incr==0 returns the heap bottom address. The second call tells _sbrk the additional space needed for the new allocation and _sbrk return the (current) top of the heap (or -1 on error).

_sbrk returns increasing pointers at each call, and, in contrast to the malloc/free pair never gives back memory or shrinks the heap space.

It should be not too difficult to insert your own bottom and top limits here instead of using the linker script variables.

hth

KnarfB

View solution in original post

4 REPLIES 4

Heap is a purely programming construct, it has absolutely nothing to do with the processor itself.

Read documentation to your toolchain if you desire to use the standard malloc/free, or simply write them yourself.

JW

KnarfB
Principal III

For gcc+newlib: Adapt the implementation of void *_sbrk(ptrdiff_t incr) in sysmem.c. _sbrk is called twice for the first malloc. The first call with param incr==0 returns the heap bottom address. The second call tells _sbrk the additional space needed for the new allocation and _sbrk return the (current) top of the heap (or -1 on error).

_sbrk returns increasing pointers at each call, and, in contrast to the malloc/free pair never gives back memory or shrinks the heap space.

It should be not too difficult to insert your own bottom and top limits here instead of using the linker script variables.

hth

KnarfB

Piranha
Chief II
PMath.4
Senior III

Thanks all. I've modified the _sbrk routine which on STM32CubeIDE and the associated HAL libraries is in syscalls.c