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
How would you be able to have your heap in serially accessed memory? Does your processor support virtual memory management, making it able to automagically swap data in or out of the SD memory?
Note that heap objects are accessed using standard pointers, so the processor expects a heap object to be possible to make operations on as if stored in normal RAM.
The file system (most probably working with your SD memory) needs RAM buffers. But these RAM buffers can't be in same technology as the SD memory, or the file system code wouldn't have needed them in the first place.
Why does your file system library need so much RAM? For large file systems, a fs driver can't expect to at the same time be able to store the full allocation data (FAT tables or whatever the specific file system uses) and a significant number of directories and a significant amount of file data in RAM at the same time. Even a full PC normally needs to move meta data in/out from the file system since huge file systems can have a gigabyte or more of allocation tables and directory entry information. It's a constant trade off between performance and resources and a reason why there are so many different file systems and file system implementations in existence.
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)
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.
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.
View all questions in Keil forum