DAVE TIP of the day: How to run all functions in one object file from PSRAM?

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
Not applicable
If you would like to run all functions in one object file (eg. MyObject_SRAM.o) from PSRAM. You can make some changes in both startup file (eg. startup_XMC4500.s) and linker descript file (*.ld):

1) Exclude the object file which will be copied to PSRAM in *.ld by replacing
*(.text .text.* .gnu.linkonce.t.*);
with
  /* exclude the object file that will run from PSRAM from Flash */
*(EXCLUDE_FILE( *MyObject_SRAM.o) *text* )
*(.gnu.linkonce.t.*);

2) Define a new section in *.ld and list the copied object file before "/*Heap - Bank1*/"
/*===  SRAMCode section for PSRAM code ============*/  
SRAMCodeLoad = eROData + __Xmc4500_Data_Size;

SRAMCode_Section : AT (SRAMCodeLoad)
{
SRAMCodeStart = ABSOLUTE(.);

/* list the object files running from PSRAM here*/
*MyObject_SRAM.o(*text*);


. = ALIGN(4);
SRAMCodeEnd = ABSOLUTE(.);
} > PSRAM_1
SRAMCodeSize = SRAMCodeEnd - SRAMCodeStart;


3) Add a copy process in startup_XMC4500.s before "SKIPSRAMCODECOPY:"
/*========== SRAM code copy  ===========================*/    
SKIPDATACOPY:

/* R0 = Start address, R1 = Destination address, R2 = Size */
LDR R0, =SRAMCodeLoad
LDR R1, =SRAMCodeStart
LDR R2, =SRAMCodeSize

/* Is there anything to be copied? */
CMP R2,#0
BEQ SKIPSRAMCODECOPY

/* For bytecount less than 4, at least 1 word must be copied */
CMP R2,#4
BCS STARTSRAMCODECOPY

/* Byte count < 4 ; so bump it up */
MOV R2,#4

STARTSRAMCODECOPY:
/*
R2 contains byte count. Change it to word count. It is ensured in the
linker script that the length is always word aligned.
*/
LSR R2,R2,#2 /* Divide by 4 to obtain word count */

/* The proverbial loop from the schooldays */
SRAMCODECOPYLOOP:
LDR R3,[R0]
STR R3,[R1]
SUBS R2,#1
BEQ SKIPSRAMCODECOPY
ADD R0,#4
ADD R1,#4
B SRAMCODECOPYLOOP
/*=================== end of Copy process =================*/
0 Likes
3 Replies
Not applicable
Sophia,
isn't it possible to post a complete small project with one or two functions executed in RAM?
This could more easily used as a template for such kind of projects.


Regards
Heinz
0 Likes
Not applicable
Yes, that would be very helpfull.
0 Likes
Not applicable
Hi,

Attached is an example using old startup and linker script template.



Best regards,
Sophia
0 Likes