heap in external SRAM


1 comment

  • Avatar
    Dr Danish Ali

    I know this was asked a LONG time ago, but I've just hit a similar problem and I'd like to share my solution.

    The problem essentially is that the heap memory needs to have some key values written to it to indicate its size and that it is empty.

    Your processor tries to write those words to the heap before main() is called - hence before anything like ctl_board_init() is called to set up the GPIO ports and identify the appropriate pins as being under the control of the memory-controller peripheral (FMC / FSMC). Because (at reset) all those GPIO pins are floating inputs, the writes never actually put these vital values into the external memory. So when you come to use the heap everything falls over.

    The same problem occurs if you have any C++ objects with constructors in external memory - the constructor tries to build the object but can't actually put it into external RAM.

    The solution I found was to define a routine (with C linkage) called void SystemInit(void); this gets called before the heap and any C++ constructors are called. SystemInit must enable the clocks to the GPIO lines and do whatever else is necessary for them to work with your external memory.

    Hope this helps,


    Comment actions Permalink

Please sign in to leave a comment.