My idea is to build this project to have the stack, the interrupt
vector table and the startup code be placed into internal RAM, but all
the other code and data into external RAM. My only problem is that I’m
not sure whether it can work or not and how can I achieve this.
It's possible and the way I'm pursuading with my E2214 board indeed.
I think I’ll have to tell LD to link the project this way
Yes, but ld.script (LD linker script for code layout) is not complicated so much.
initial code (== startup code in your words) is carefully designed as “position independent”, in which code is to use program counter relative addresses (+/- offset of current instruction running at any moment) to load/store/jump ops. Not worry; ARM code is mostly position independent besides explicit absolute address references.
initial code copies TEXT and DATA from flash to external SRAM.
these are linked against CS1 (0x8100’0000) external SRAM address region.
initial code is part of TEXT whose link address is CS1, but it can run ok since it’s designed position independent while running around internal flash address region (0x0000’0000~).
initial code prepares zero cleared BSS segment in CS1.
initial code assigns stack pointer with an address somewhere in internal SRAM (it’d be plain easy to have external SRAM stack instead).
initial code copies vector table (64 bytes) to 0x4000’0000 of internal SRAM region. ARM vector table takes the following convention in most cases;
I was vague about ld.script for CS1. Since your TEXT+DATA will be in train, there is no need to have fancy ld.script after all. Just should be ok to have;
$(LD) -e _start -Ttext 0x81000000 ...
here _start is the very beginnig of TEXT. You may check how the entire address was laid out with “nm -Bon” command. The resulting .hex executable image can be written straight in flash.