Using program scratch pad

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

cross mob
User21716
Level 1
Level 1
Hi,

I have been trying to execute some of my codes to PRSR (program scratch pad RAM).

In the linker script, I did the following:
group (contiguous, ordered, run_addr = mem:int_ram_core0_P, copy)
{
select ".text.MyModule.SampleFunction";
}

But here the actual instruction code are missing (see only nop).
5118.attach

How do I actually do this?
Note: mem:int_ram_core0_P points the PRSR address.
0 Likes
10 Replies
teoBits
Employee
Employee
5 sign-ins 100 replies posted 50 replies posted
Hello,

did you altready take a look at the RAM_RUN_Function_1 trainings?
They also come with a detailed tutorial here: RAM_RUN_Function_1 tutorial

Note: I linked the training for the Lite Kit featuring AURIX TC375, but the same training is also available for TFT kits featuring AURIX TC297 and TC397

hope it helps,
teoBits
0 Likes
User21716
Level 1
Level 1
Hello,

Thanks for your reply.

I did similar to the one mentioned in the training slide / git.

Like this in my lsl:
group (ordered, attributes=rwx, copy, run_addr = mem:int_ram_core0_P)
{
select "(.text.*.cpu0_psram|.text.*.cpu0_psram.*)";
}

In my code:
#pragma section code cpu0_psram
void MySampleFunction(uint8* u8X)
{
*u8X = 50;
}
#pragma section code restore

However I still see the following generated assembly (without the actual instruction code):
5134.attach

Is there some code/instruction where the actual code is copied to program scratch pad? I thought the copy attribute is doing that?
0 Likes
teoBits
Employee
Employee
5 sign-ins 100 replies posted 50 replies posted
Did you try adding some more code instructions inside the function? maybe the compiler is optimizing your code because the function is really simple.

teoBits
0 Likes
User21716
Level 1
Level 1
Yes, I did add some more codes. Actually, I initially added an existing function in my project, but then I noticed only "nop" all over (e.g. memset, memcpy functions).
Also I made a similar function like posted above (setting different value) and place it in segment 8 (where most of our codes are located), there I see a correct assembly instructions.
0 Likes
ScottW
Employee
Employee
10 sign-ins First solution authored First like received
Does the problem persist if you declare u8X as volatile? I.e.:

void MySampleFunction(volatile uint8* u8X)


Edit: This should help with the nops. Note that the function itself is already in CPU0 PSPR.
0 Likes
User21716
Level 1
Level 1
Hello,

I tried just now putting a volatile and I still see nop in the assembly.

Here is the screenshot:
5126.attach

Could you explain a bit more how the code data are being copied to the program scratchpad at the beginning? Is there something else I should be checking?

Update:
I also checked the content of the address and I only see 0x00 (corresponding to nop):
5127.attach

Btw: I really appreciate the support I am getting from this forum. Especially to the infineon colleagues.
0 Likes
User21716
Level 1
Level 1
Hi again,

I found out in the project I am working on the following link option is active:
--user-provided-initialization-code

I also check our code of boardStart, we are not calling _c_init because we are doing custom initialization.
This means I think that the copytable is not used to initialize RAM from ROM (including the program scratchpad).

My question now is:
How can copy the code to program scratchpad while using custom initialization? Our project already kind of rely on this custom initialization therefore I cannot revert to _c_init...

Thanks in advance!
0 Likes
NeMa_4793301
Level 6
Level 6
10 likes received 10 solutions authored 5 solutions authored
That's a good question for your compiler maker. But every compiler's copytable has tricky business, so re-inventing that wheel is fraught with danger.
0 Likes
ScottW
Employee
Employee
10 sign-ins First solution authored First like received
As UC_wrangler mentioned, you probably won't want to use the copytable directly.

You could remove the PSPR directive so the function is placed in flash. If you then reserve an area of PSPR, you could copy the function from the known location in flash to the reserved location in PSPR and execute it from there. This does have potential issues from a maintenance perspective: it's important to make sure that the reserved space is always large enough to hold the function as compiled.
0 Likes
User21716
Level 1
Level 1
Hello,

I am not sure if this will work out because even if I copy my code from flash to PSPR, any code that calls my code will still jump to original location address in the flash and not in location address in the PSPR because was known location address at link time.
Or did I understand it differently?
0 Likes