This text will describe how use the same RAM to run different code at different times, by copying ROM-content from several different segments to the same addresses in RAM.
See Technical Note 80460 about the basics about copying content from ROM to RAM.
This Technical Note applies to versions that uses IAR XLINK Linker.
The following steps must be taken to overlay several code segments in RAM:
See Technical Note 80460.
Note that "built in" keywords (like __ramfunc) typically do not work when you want to place content in two (or more) different segments. You probably have to use the #pragma approach.
See Technical Note 80460.
-QRAMCODE1=RAMCODE1_ID
-QRAMCODE2=RAMCODE2_ID
IAR XLINK Linker has a placement modifier for the -Z segment placement command, @, that ignores previously placed content in the placement range.
-Z@(DATA)CODE_A,CONST_A,DATA_A=RAM_OVERLAY_START-RAM_OVERLAY_END
The -Z@ command obeys all the normal rules for -Z, it just ignores any previously placed content in the range. The segments will be placed in the specified order starting on the address RAM_OVERLAY_START.
Then place the next overlay on the same address:
-Z@(DATA)CODE_B,CONST_B,DATA_B=RAM_OVERLAY_START-RAM_OVERLAY_END
This will place the specified *_B-segments on the same addresses that the *_A segments used. This creates an intentional overlap where multiple RAM-segments have the same addresses.
IAR XLINK Linker will detect the segment overlaps and generate errors for them. The overlap error can be turned off, or changed into a warning. The problem is that turning the error off will result in real overlaps being ignored as well. Changing the error into a warning will result in several warnings every time the program is linked. There is a linker option --disable_overlap_check that allows you to selectively turn the overlap error off for specified segments overlaying.
Use ...
--disable_overlap_check=CODE_A,CONST_A,DATA_A,CODE_B,CONST_B,DATA_B
... to turn off the segment overlap error for the involved segments. This turns the overlap error off for the involved segments, but only if it overlaps another of the involved segments. Overlaps between CODE_A and some other segment (that might, or might not, be listed in another --disable_overlap_check option) will still be reported.
See Technical Note 80460.
-Z(CONST)CODE_A_ID,CONST_A_ID=ROMSTART-ROMEND
-Z(CONST)CODE_B_ID,CONST_B_ID=ROMSTART-ROMEND
See Technical Note 80460.
The case with overlaid RAMCODE segments is quite a bit more complex than the case of a single RAMCODE segment. These are the most important aspects:
All product names are trademarks or registered trademarks of their respective owners.