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

place heap in external location

Has anyone been successful in setting up the Keil tools and changing the Startup.s file to place the heap in external location (on SD/MMC Card or off-chip memory)?

The only reason that I want to use external memory is because I am using a library for the file system that needs to dynamically allocate space. The amount of space it needs to allocate is more than I have in internal memory.

Iam working on LPC2378 with keil uvision4.

Any help will be appreciated. Thanks in advance

Parents
  • Thanks very much for your reply. What could be the other options available? Because my RAM is only 32KB. To my knowledge (RW Data + ZI Data) will make use of RAM and in my code it completely uses the RAM. But still I could n't allote the required memory. Normally what could be the options available if application needs more memory (dynamic memory)

Reply
  • Thanks very much for your reply. What could be the other options available? Because my RAM is only 32KB. To my knowledge (RW Data + ZI Data) will make use of RAM and in my code it completely uses the RAM. But still I could n't allote the required memory. Normally what could be the options available if application needs more memory (dynamic memory)

Children
  • The only real option is to fit more physical memory - either by using a microcontroller with more internal memory, or by adding suitable external memory.

    Note that many microcontrollers do not have any facility to add external memory.

  • Isn't your RAM is 32k + 16k + 8k + 2k if you don't need the extra RAM regions for other things?

    If you need more RAM, your only option is to get more RAM. Either a chip with more RAM, or - as the LPC2378 have support for two external 64kB memory regions - add external RAM.

    But the compiler expects RAM to be that Random Access Memory. In this case, the compiler requires the addresses to be directly accessible. That isn't true with any serially connected memory.

    The other option is to check closer what you need and what you really do with your RAM. Maybe you have things in RAM that could have been in flash as const data. Maybe you have things in RAM that could be stored on the SD memory card and only read in when needed. Maybe you have too large buffers. Or too many buffers.

  • Is it??

    You said you're using LPC2378

    According to http://www.keil.com/dd/chip/4153.htm the LPC2378 has 58KB RAM.

    It also says, "External Memory Controller for static devices such as Flash and SRAM" - so you could add external RAM.

  • Thanks Per and Andrew for ur valuable suggestions. Yes my RAM is 32k + 16k + 8k + 2k where in which 32K is for SRAM and remaining for USB, Ethernet etc., As of now in my application, in the Options for Target, my IRAM1 start is 0x40000000 and size is 0x8000. How can I make use of the additional RAM?

    Also how to configure external RAM in my application? What settings I need to make?

    Thanks in advance

  • If you turn on the power to the Ethernet device, then you can open your project settings and add the start address and size of the 16kB Ethernet RAM as second memory region.

    If you make use of the scatter file, you can add the start address and size of the USB RAM too (but remember to turn on the power) and if you have power supplied to the VBAT pin you can add the 2kB of battery-backed RAM to the scatter file too.

    Adding the individual RAM regions to the project is only needed if you want the compiler/linker to be able to place variables in these memory regions. It's possible to place a stack or a heap or large buffers in these memory regions without specifying the memory region in scatter file or project file. This can be done using either absolutely located variables or by using pointers. Just note that if the startup file doesn't know about the extra RAM regions, then they will not be zero-initialized when your program boots. On the other hand, you normally don't want the battery-backed RAM to be zero-initialized on every reboot since that destroys the usefulness of having a backup battery.

    One thing to remember is that the extra memory regions do have some limitations when it comes to DMA transfers, ISP for reprogramming the flash or for code execution from RAM.

  • Thanks Per

    It's possible to place a stack or a heap or large buffers in these memory regions without specifying the memory region in scatter file or project file.

    Can you please explain me a little bit more about how can we acheive this one?

  • You probably have something similar to:

    ; <h> Heap Configuration
    ;   <o>  Heap Size (in Bytes) <0x0-0xFFFFFFFF:8>
    ; </h>
    
    Heap_Size       EQU     0x00000000
    
                    AREA    HEAP, NOINIT, READWRITE, ALIGN=3
    __heap_base
    Heap_Mem        SPACE   Heap_Size
    __heap_limit
    


    in your startup file. You can explicitly control where HEAP should be located. Or you can just add more memory regions to the project and have the linker figure out where there are free space to store the HEAP.

  • You can place the stack/heap using a scatter file, like this:

      IRAM_STACK 0x40002040 0xE000 {  ; RW data
        LPC2400.o (STACK)
        .ANY (+RW +ZI)
      }
    

    since the linker creates a sections called STACK and HEAP.