cancel
Showing results for 
Search instead for 
Did you mean: 

Create large objects in STM32F429Disco SRAM

Just Matt
Associate III
Posted on October 24, 2017 at 02:57

Hi all,

I'm somewhat new to the micro world of development. I am trying to create a fairly large object in the SRAM on the F429Disco.

I am using the FMC_SDRAM example provided by ST. It compiles and run fine Out of the box, so I wont clutter up the thread with all that code. 

/* Program the SDRAM external device */

SDRAM_Initialization_Sequence(&hsdram, &command);

Right after the above code, I try to creating some large arrays by using a new char and a vector.

char *pMem = new char[4000000];

for(int i = 0; i< 4000000 - 1; ++i)

{

pMem[i] = 0xAA;

}

delete[] pMem;

The above code goes into a hard fault, I notice that the address of the pointer is 0x20000910 which is not in the SRAM region. Therefore, when I try to initialize the object with 0xAA it goes to hard fault.

When I try to create a vector, same result vector<char> data(4000000); causes death when I try to initialize.

How can I create a large array (block of memory) in the external SRAM? 

Thanks in advance!

#ionlycodeontheweekends #newbie #c++11 #stm32f429-discovery
4 REPLIES 4
Jan Waclawek
Senior II
Posted on October 24, 2017 at 03:17

Look up in your toolchain's documentation, how heap is allocated to external SDRAM in your particular toolchain - this is toolchain dependent.

Please note the D letter in SDRAM - it's important; SRAM (without the D) refers to an entirely different type of memory, and in context of STM32 it usually means the internal RAM.

JW

Posted on October 24, 2017 at 03:40

Thank you for responding! Seems like I need to update the linker script or add in some flags to the linker so it is aware of the extra SDRAM

Posted on October 24, 2017 at 04:59

In GNU/GCC, the linker script should be aware, you should place the heap in the SDRAM section, and initialize the SDRAM before the startup code initializes statics, constructors, etc.

In Keil, the SDRAM gets defined in the Scatter File, the Heap gets directed into the SDRAM's Load Region, and the heap size is specified in the startup_stm32f4xx.s, there are other tricks to define multiple arenas for the heap allocator to select from.

 

 

SDRAM on the STM32F4 is relatively slow, you don't want to put the stack there, and ideally smaller and fast structures should live in Internal SRAM

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on October 24, 2017 at 05:05

On the GNU front you'd need to tinker with _sbrk, at the moment it uses the stack to delimit the heap size, and you really don't want the stack in SDRAM as it is slow, and therefore crush performance if used by every routine in your app.

 

Bunch of dead links in there which failed to get converted when the forum was ported to Jive, will try and fix those in a bit.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..