Skip to main content
Just Matt
Associate III
October 24, 2017
Question

Create large objects in STM32F429Disco SRAM

  • October 24, 2017
  • 4 replies
  • 1381 views
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
This topic has been closed for replies.

4 replies

Jan Waclawek
Visitor II
October 24, 2017
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

Just Matt
Just MattAuthor
Associate III
October 24, 2017
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

Tesla DeLorean
Guru
October 24, 2017
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 (See Profile) Up vote any posts that you find helpful, it shows what's working..