Showing results for 
Search instead for 
Did you mean: 

STM32f429: problem with using external SDRAM as an additional data memory

Mohammad Hossein
Associate II


I can read/write an external sdram using fmc in stm32f429. But working with address and read/write functions is not proper for my purpose. I want to introduce external sdram as if internal sram is clearly extended and whenever I define a big variable it is projected to external sdram automatically.

I checked stm32f4 cubemx repository examples (SDRAM+DATAMEMORY) and searched a lot but it seems this is not straightforward.

Following these steps based on what I found, I get hardfault after system_init.

1) Defining external sdram address and size in the linker (off-chip ram)

2) Adding some code in startup_stm32f420xx.s

3) Defining DATA_IN_ExtSDRAM for initializing sdram before main function

4) Enabling system clock before main function

My external sdram is connected to SDRAM1 in stm32f429.

What is the correct procedure? Is SystemInit_ExtMemCtl() function implemented correctly? Is any modification needed? Is enabling clock before main function and after system_init needed?

Here I attached the modification I did according to my searches and examples.

Can anyone tell what is the correct code step by step?

Thanks in advance.


Harvey White
Senior III

I have the SDRAM working properly, and can store variables there.

In the FMC, you need to set the appropriate address as well (check to see where SDRAM is mapped).

The initialization code for the SDRAM is incomplete. While you set up the FMC properly, you must also init the SDRAM (check the data sheet). It requires additional code added into one of the user areas in main.c.

While that gets you working memory (and you don't change the .s file), the memory can't yet be used by the compiler.

Look to see how memory regions are mapped in the linker file, and add a specific region that is mapped to where the memory is supposed to be. This tells the linker where it can put things.

Then there are specific instructions to locate a variable into that memory region.

Once you do all that, you're good to go.

A little involved, but that's how I did it.

I have XRAM (extended RAM), my symbol for it, that I can use without a problem. If you're using FreeRTOS, there are a few other steps, but they work.