cancel
Showing results for 
Search instead for 
Did you mean: 

SPC5 code call from flash to RAM

MDupo.1
Associate

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 discussion has been locked for participation. If you have a question, please start a new topic in order to ask your question
1 ACCEPTED SOLUTION

Accepted Solutions
Erwan YVIN
ST Employee

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

View solution in original post

2 REPLIES 2
Giuseppe DI-GIORE
ST Employee

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
ST Employee

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