We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
How do I configure the HEAP to be placed within the external memory?
I'm using an LPC1778 with 2MB external memory. I want the controller to calculate an a*-algorithm on a bitmap (loaded from sd-card). Thus, i need lots of dynamically allocated memory (by malloc/realloc).
While searching the forum i only found this: http://www.keil.com/support/man/docs/armlib/armlib_CHDJHFGB.htm .
Can anybody tell me how and where to set the __heap_base to 0x80000000 and the __heap_size to 0x100000?
The linker should place your heap in external memory automatically once its maximum size grows (.s file) and you use scatter loading and place an .ANY (+RW +ZI) in it for the external memory execution region. I think the linker also emits symbols for this - something containing "HEAP" maybe? Check your linker manual.
This is how my scatter file looks out now:
LR_IROM1 0x00000000 0x00080000 { ; load region size_region ER_IROM1 0x00000000 0x00080000 { ; load address = execution address *.o (RESET, +First) *(InRoot$$Sections) .ANY (+RO) } RW_RAM1 0x80000000 0x00200000 { ; RW data sram.o (+ZI +RW) .ANY (+RW +ZI) } RW_IRAM1 0x10000000 0x00010000 { .ANY (+RW +ZI) } }
Unfortunately, if i try to Debug my program, i run into the HardFaultHandler even before main() is called. Within the linker options inside uVision4 i have deselected "Use Memory Layout from Target Dialog" and set the R/W Base to 0x80000000. Has anyone an idea?
try adding this to RW_IRAM1 zone:
x.o (STACK)
x = the name of your startup (.s) file.
It works! Thank u so much!
If external RAM is initialized via a function call - unlike the Keil LPC2400 implementation that are confined to the startup file - and if the linker places the processor stack in external RAM rather than internal RAM, you are dead once the code that initializes the external RAM attempts to return, or even before that.
The heap and stack are initialized in the startup file. since the external memory is initialized in a C function, this will never work on that way. because the C function tries to use the stack and heap (on the external memory) which isn't initialized yet.
I've had the same problem with my EA lpc1788 dev board. I've added the C function initialization of the external memory to the startup file (in assembly) The startup code will initialize the external memory and after that, still in startup file, the Heap and Stack are placed in the external memory. when the program jumps to the C code functions, it will use the heap and stack on the initialized external memory.