This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Allocate HEAP into external SDRAM with Keil-RTX

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 to 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 next scatter 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 SRAM IS61LV51216, 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.