Skip to main content
MDupo.1
Visitor II
December 8, 2020
Solved

SPC5 code call from flash to RAM

  • December 8, 2020
  • 2 replies
  • 1131 views

Hi,

I've got the latest SPC5Studio 6 with all updates (gcc4.9.4) and testing on the SPC560D40L1 chip with the discovery board. So core is e200z0h VLE.

I want to manipulate the flash in my app so I need to call some code from the RAM. I added the necessary sections in the application.ld, and the necessary attribute for my method :

__attribute__ ((section (".codeinram"))) void method_in_ram()

I'm calling this method from flash code

void flash_method() {

method_in_ram()

}

All this compile correctly (no warning, no error), but this crashes during debug with invalid opcode...

I decompiled the hex, found that the flash_method content is not VLE code but PPC code !! e200z0h does not support PPC but only PPC VLE. Why is gcc creating PPC opcodes to call a method in RAM ? I tried to add longcall attribute but it does not help ...

Any help appreciated!

Thanks

    This topic has been closed for replies.
    Best answer by Erwan YVIN

    Hello ,

    There are some examples in SPC5Studio.

    you have to create user.ld at the root of the project. (cf user.log in attachment)

    __attribute__ ((section (".codeinram"))) void gotoStandbyMode(void) {
     
    	WKUP.WISR.R = 0x00000008;		//Clear interrupt flag
     
    	if ((ME.GS.B.S_CURRENTMODE < SPC5_RUNMODE_RUN3)
    	 || (ME.GS.B.S_CURRENTMODE > SPC5_RUNMODE_RUN0)) {
    	 if (OSAL_FAILED == halSPCSetRunMode(SPC5_RUNMODE_STANDBY)) {
    	 SPC5_CLOCK_FAILURE_HOOK();
    	 }
    	 }
    }
     
    __attribute__ ((section (".codeinram"))) void gotoRunMode(void)
    {
    	 if (OSAL_FAILED == halSPCSetRunMode(SPC5_RUNMODE_DRUN)) {
    	 SPC5_CLOCK_FAILURE_HOOK();
    	 }
    }

    Best Regards

    Erwan

    2 replies

    Giuseppe DI-GIORE
    ST Employee
    January 11, 2021

    Hello,

    did you manage to copy the code from flash to RAM before executing it ?

    could you share the application.ld ?

    Regards,

    Giuseppe

    Erwan YVIN
    Erwan YVINBest answer
    ST Employee
    February 4, 2021

    Hello ,

    There are some examples in SPC5Studio.

    you have to create user.ld at the root of the project. (cf user.log in attachment)

    __attribute__ ((section (".codeinram"))) void gotoStandbyMode(void) {
     
    	WKUP.WISR.R = 0x00000008;		//Clear interrupt flag
     
    	if ((ME.GS.B.S_CURRENTMODE < SPC5_RUNMODE_RUN3)
    	 || (ME.GS.B.S_CURRENTMODE > SPC5_RUNMODE_RUN0)) {
    	 if (OSAL_FAILED == halSPCSetRunMode(SPC5_RUNMODE_STANDBY)) {
    	 SPC5_CLOCK_FAILURE_HOOK();
    	 }
    	 }
    }
     
    __attribute__ ((section (".codeinram"))) void gotoRunMode(void)
    {
    	 if (OSAL_FAILED == halSPCSetRunMode(SPC5_RUNMODE_DRUN)) {
    	 SPC5_CLOCK_FAILURE_HOOK();
    	 }
    }

    Best Regards

    Erwan