Skip to main content
PMath.4
Senior III
January 30, 2021
Solved

STM32H743: Moving the heap into SDRAM?

  • January 30, 2021
  • 4 replies
  • 1242 views

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

This topic has been closed for replies.
Best answer by KnarfB

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

4 replies

waclawek.jan
Super User
January 30, 2021

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
KnarfBBest answer
Super User
January 30, 2021

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
Principal III
January 30, 2021
PMath.4
PMath.4Author
Senior III
January 30, 2021

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