cancel
Showing results for 
Search instead for 
Did you mean: 

Allocate HEAP into external SDRAM with Keil-RTX

y_
Associate
Posted on November 24, 2015 at 09:02

Hello!

I'm developing an application which requires the heap to be located in a 32MB off-chip SDRAM. I'm using Keil RTX in the project.The problem is the application falls when a function malloc() is calling.

The crystall used is

STM32F746IG

. The external SDRAM is MT48LC16M16A2P.There are absolutely clear project with only

RTX_CM4.lib

,

RTX_Conf_CM.c

,

startup_stm32f746xx.s

and

system_stm32f4xx.c

files.

I have #define DATA_IN_ExtSDRAM in

system_stm32f4xx.c

file t

o initialize SDRAM.

If there is no scatter file in the project - the memory is working correctly: in this case i can write some data to the memory and read from one in [0xC0000000 to 0xC2000000] 32MB range.

But if i have create the nextscatter file to allocate HEAP into external SDRAM, there is an hard-fault handler exception when the malloc() function is called.

LR_IROM1 0x08000000 0x00100000 { ; load region size_region
ER_IROM1 0x08000000 0x00100000 { ; load address = execution address
*.o (RESET, +First)
*(InRoot$$Sections)
.ANY (+RO)
}
RW_RAM1 0xC0000000 0x02000000 { ; RW data
;.ANY (+RW +ZI)
*(HEAP)
}
RW_IRAM1 0x20010000 0x00040000 {
.ANY (+RW +ZI)
}
}

start-up file:

Stack_Size EQU 0x00000400
AREA STACK, NOINIT, READWRITE, ALIGN=3
Stack_Mem SPACE Stack_Size
__initial_sp
Heap_Size EQU 0x00000200
AREA HEAP, NOINIT, READWRITE, ALIGN=3
__heap_base
Heap_Mem SPACE Heap_Size
__heap_limit
PRESERVE8
THUMB

main.c

listing where malloc() is calling is presented below:

#include ''cmsis_os.h''
#include <stdlib.h>
int

main(

void

)
{
uint16_t* p;
uint16_t data;
p =

malloc

(10);
*p = (uint16_t)0x22DD;
data = *p;
}

There is no Microlib in the project!

One interesting thing is that if Microlib is checked in the project settings, the malloc() function is work correctly, but failed without it. But using RTX

without microlib

is very important for our projects.

And the other interesting thing is that i have

absolutely identical project

on the

STM32F407IGT6

crystal with external SRAMIS61LV51216, and there is no such problem on them. I have identical scatter file, identical#define DATA_IN_ExtSRAM, and no microlib. But malloc() calling is work correctly.

#!stm32-!heap-!sdram-!malloc
2 REPLIES 2
Posted on November 24, 2015 at 13:24

Well it sounds like you need a Hard Fault Handler, and to dig into what exactly the processor is objecting too and where. You'll need to drill into the allocator, and instruction/location faulting.

I'd probably add some code prior to the malloc() to clear the SDRAM, proving that writing zeros to it does actually work at this point.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
stephani
Associate
Posted on April 11, 2016 at 12:31

Hi, i have the same problem. Do you have any solution in the meanwhile?