Executing FLASH002 from RAM

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

cross mob
Not applicable
Hi,
I just tried the FLASH002 app in a simple project that toggles the user LED on the XMC4400 Hexagon Application Kit. My project simply erases Sector 9 (the 256 KB sector in the XMC4400) and the writes a few pages pages on this flash sector (S9).

The code that does that (all the erasing and programming) is called from the int main (void) routine and gets automatically located by the tool chain in the first sector of flash (S0).

I noticed that the code executes from FLASH, and as expected, the execution temporarily halts while the erase and program command sequences are being executed.

I have two questions:
1 - Is there a (easy) way to execute the FLASH002 app from RAM? The Help document for this App states that these functions may be executed from RAM, but does not provide any details as to how to achieve this.
2 - Are there non-blocking versions of erase / program functions(Flash002_EraseSector & Flash002_WritePage)? (I mean, functions that do not wait until the operation is finished)

Thanks,
Luis
0 Likes
3 Replies
Charm
Employee
Employee
5 sign-ins First like given 5 replies posted
On 2) I don't think this is possible due to the nature of the On-chip Flash. The reason to run from RAM is so that can execute key functions while Flash is busy. Key functions include interrupt and exception handling.

So to question 1) on how to execute from RAM.
Code needs to be on Flash anyway as RAM loses its content on power-off.
During runtime, copy this code from Flash to RAM, jump and execute.

Hope this helps!
0 Likes
AndreasG
Employee
Employee
10 replies posted 5 replies posted Welcome!
I seem to remember that in the example project of the FLASH002 app the program and erase routines are copied into the RAM.
Details on how this is done you will have to get from a software expert 🙂
0 Likes
Not applicable
All right, so I write this as an update.

I found that both things are possible and actually, pretty easy.

1) In the current version of Infineon DAVE at the time of this writing (v3.1.10), you only have to add __attribute__ ((section (".ram_code"))); in the declaration of a function.
For example, I modified FLASH002 by declaring ...
status_t Flash002_EraseSector (uint32_t Address) __attribute__ ((section (".ram_code")));

The linker directives file (*.ld) contains (or, should contain) a section called ram_code which is put into PSRAM or DSRAM.

2) I wrote my own version of the FLASH002 functions, in order to make them non-blocking. When you see the code it is obvious where the function waits for the operation to complete (sample taken from the Flash002_EraseSector function):

/*wait until the operation is complete*/
while (FLASH0->FSR & FLASH_FSR_PBUSY_Msk)
{
/*do nothing*/
}

So I removed that wait and came up with the non-blocking version.

In my version I now am:
+ Executing from RAM
+ Not blocking when waiting the flash operations to complete (11 ms for a write and around 5 or 6 seconds for a sector erase in a XMC4400)

The advantage is that I can now execute some highly critical control algorithms, from RAM, while the flash memory is unavailable.

Thanks for the help.
0 Likes