cancel
Showing results for 
Search instead for 
Did you mean: 

how to use sdram as a ram used by compiler

jones.david
Associate II
Posted on August 03, 2015 at 10:29

hi all

i use an external SDRAM in my board. i want to use STEmwin in my program but when i use one of Segger sample in my program an error appear and tells that there is not enough space ( some thing like this''no space .... .ANY'' ) in RAM.

So i decide to Set compiler that uses  External SDRAM as  RAM like internal Ram.

i then go to Option->Target and add offchip ram Start=0xd0000000,Size=0x01c000000

 (''my external Sdram size is 0x02000000 32MB and i Use 0x01c00000-0x01e00000 for LTDC layer0 buffer and 0x01e00000-0x02000000 for LTDC layer1'')

it  temporarily correct compiler error but when i load programm in MCU an error occures that core is halted

i then do lot of search and all i found was i must init SDRAM Before declaring Variable so i Use System_Init Function Template to initialize SDRAM. i notice that the template mostly use Registers to initialize SDRAM but in some cases to make Delay uses some local variables and exactly in those place system goes to HardFault_Handler.

i then try to initial Stack to use Internal Ram in startup file

Initial_sp EQU 0x20000000+StackSize

result was core is halting(i even could not enter debug mode)

then i try to initialize Those Local Variable in System_init As Global and Attribute them Separately to be in Internal Ram

For example like below

volatile uint32_t tmp __attribute__(at(0x20000000));

the core again halt

i then saw an example in a

https://github.com/MaJerle/stm32f429/tree/master/14-STM32F429_SDRAM_VARIABLES

that claims to use external ram but i tested it in f429 disco and it wont work (see it's scatter file)

 any help is appreciated
3 REPLIES 3
Posted on August 03, 2015 at 14:44

You're using what tool chain?

Usually you want to define all the regions of memory, and then direct specific allocation into these regions/sections. I wouldn't use the AT directive, I would define the sections in the linker script or scatter file, and then tag the specific allocation. Another approach would be to keep small static allocations in Internal SRAM, and use the SDRAM as a dynamic allocation pool, and allocate the large buffers once.

Normally external memories need to be initialized by code in or called by SystemInit(), which is called prior to the C Runtime code which initializes your statics before calling main()

https://my.st.com/public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/Flat.aspx?RootFolder=https://my.st.com/public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/Make%20use%20of%20the%2064k%20CCM&FolderCTID=0x01200200770978C69A1141439FE559EB459D7580009C4E14902C3CDE46A77F0FFD06506F5B&currentviews=6170

covers how to use and direct data into CCM RAM, but gives you a perspective on how to define and direct content into it.

I've done similar threads for the SDRAM, I will have to dig for those later, but definately posted GNU and Keil examples where SystemInit() calls SystemInit_ExtMemCtrl() tailored for the STM32F429I-DISCO

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
jones.david
Associate II
Posted on August 03, 2015 at 16:06

thanks clive1

my tool chain is Keil 5 and i use default compiler. if i understand you well i make my Scatter file like this

; *************************************************************
; *** Scatter-Loading Description File generated by uVision ***
; *************************************************************
LR_IROM1 0x08000000 0x00200000 { ; load region size_region
ER_IROM1 0x08000000 0x00200000 { ; load address = execution address
*.o (RESET, +First)
*(InRoot$$Sections)
.ANY (+RO)
}
RW_IRAM1 0x20000000 0x00030000 {
.ANY (+RW +ZI)
}
RW_RAM1 0xD0000000 UNINIT 0x02000000 { ; RW data
wm_touch.o (+ZI +RW)
guiaa_char4.o (+ZI +RW)
button.o (+ZI +RW)
framewin.o (+ZI +RW)
gui_core.o (+ZI +RW)
gui__alpha.o (+ZI +RW)
gui_curs1.o (+ZI +RW)
gui_multibuf.o (+ZI +RW)
skinning_notepad.o (+ZI +RW)
}
}

as you told i use SDRAM as large buffer ram and add my files with big variables to use sdram(i named them in SDRAM Section) and set the rest of variable to use internal ram(.ANY) this helps me finally initialize SDRAM in SystemInit Function and go to main (that's great for two days failure) but now the program goes to hard fault when i execute ''GUI_init();'' (notice that i already test my program without SDRAM and see the result in LCD.'')
jones.david
Associate II
Posted on August 03, 2015 at 17:09

Problem solved.

i forgot to clear initialize SDRAM in main.c file .because i already initialize SDRAM in SystemInit reinitialize it in main cause SDRAM went in unstable state.

Thank You CLive1.