DAVE TIP of the day: How to run an individual function 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 a particular function (eg. MyFunction_SRAM()) from PSRAM to enhance the code execution speed. You can make some changes in both startup file (eg. startup_XMC4500.s) and linker descript file (*.ld):

1) Define a new section in *.ld before "/*Heap - Bank1*/"
/*===  SRAMCode section for PSRAM code ============*/  
SRAMCodeLoad = eROData + __Xmc4500_Data_Size;

SRAMCode_Section : AT (SRAMCodeLoad)
{
SRAMCodeStart = ABSOLUTE(.);
* (.SRAMCode);
. = ALIGN(4);
SRAMCodeEnd = ABSOLUTE(.);
} > PSRAM_1
SRAMCodeSize = SRAMCodeEnd - SRAMCodeStart;


2) 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 =================*/


3) Declare function in program
void MyFunction_SRAM (void) __attribute__ ((section (".SRAMCode")));


With these, the function MyFunction_SRAM will be located in section SRAMCode. It will be copied to PSRAM in startup code and then run from PSRAM.
0 Likes
5 Replies
Not applicable
Dear Sophia

I try this tips, but i can not found "SKIPSRAMCODECOPY" in my startup_XMC4500.s file.
The image show the error after i add the step 2 code in my Startup_XMC4500.s
0 Likes
Not applicable
Hi Gun,

Sorry, forgot to mention that you need to change the "SKIPCOPY" to "SKIPSRAMCODECOPY:".

Best regards,
Sophia
0 Likes
Not applicable
Hi Sophia

After i change all mentioned "SKIPCOPY" to "SKIPSRAMCODECOPY" in file Startup_XMC4500.s, the project successfully compiled.

I declared one of my function to be put in PSRAM
void Motion_Control(void) __attribute__ ((section (".SRAMCode")));

When the program being launched in the board, the debugger suddenly stop when reached the function void Motion_Control(void).
After i execute the single step (F5), the debugger window show "No source available for "0x10000328()" and the program completely stopped.
0 Likes
lock attach
Attachments are accessible only for community members.
Not applicable
I found another error.

In "DATA COPY" you have to change BEQ SKIPCOPY to BEQ SKIPDATACOPY.

I also attached my working startup file.
0 Likes
Not applicable
Hi,

There is an example project "FunctionLocated_in_RAM" available in the internet. Key word "Code in RAM".

Best regards,
Sophia
0 Likes