cancel
Showing results for 
Search instead for 
Did you mean: 

GNU vs GHS

kb24
Senior

I am using SPC58EC. When I compile same code with GNU and GHS(Green Hills Software) I see different results.

int main(void) {
 
 
	uint8_t mode;
 
	MC_ME.PCTL[15].R = (uint8_t)18;
	mode = (uint8_t)MC_ME.MCTL.B.TARGET_MODE;
 
	//SPCSetRunMode
	/* Clearing status register bits */
	MC_ME.IS.R = 0x3FU;
 
	/* Starts a transition process.*/
	MC_ME.MCTL.R = (mode << 28) | 0x5AF0UL;
	MC_ME.MCTL.R = (mode << 28) | 0xA50FUL;
 
	/* Waits for the mode switch or an error condition.*/
	while (MC_ME.IS.R == 0U) {
	;
	}
	/* Check if no error during mode switch */
	if (MC_ME.IS.B.I_MTC != 1U)
	{
		while(1);
	}
 
	SIUL2.GPDO[88].R = 0;
	SIUL2.MSCR_IO[88].R = ((2 << 24) | (1 << 23));
 
	SIUL2.GPDO[89].R = 0;
	SIUL2.MSCR_IO[89].R = ((2 << 24) | (1 << 23));
 
  
  /* Application main loop.*/
  for ( ; ; ) {
	  SIUL2.GPDO[88].R = ~SIUL2.GPDO[88].R;
	  SIUL2.GPDO[89].R = ~SIUL2.GPDO[89].R;
	  for(long i=0;i<10000000;i++);
  }
}

All code is this, I am not using library functions. Startup files are almost same only order of ram init, interrupt vector init etc. is different. In GNU version I can toggle LED, but in GHS version I cant modify SIUL2 registers, so I cant do settings or toggle the output. Why is this happening? Cant we compile SPC5 studio example codes with GHS?

1 ACCEPTED SOLUTION

Accepted Solutions
ODOUV.1
ST Employee

As you removed all ST libraries, I wonder if you also removed the stuff done at boot in clock.c

void __early_init(void) {

 spc_clock_init();

}

removing that, I cannot toggle the led either.

BRs,

-Olivier

View solution in original post

15 REPLIES 15
kb24
Senior

0693W00000Lx6hNQAR.pngI found a difference from startup files. GNU version is setting Master Reload Signal(MSR), not setting that value causes any error?

ODOUV.1
ST Employee

Hello,

I suppose this line was removed by GHS compiler optimizer

38 for(long i=0;i<10000000;i++);

try with "volatile long"

Best regards,

-Olivier

Yes you are right but SIUL2.MSCR_IO[88].R = ((2 << 24) | (1 << 23));

this isnot working also. I debugged assembly code, compiler didnt optimize this, also in debug screen(winIdea) I can change other registers but I cant modify SIUL2 registers.

ODOUV.1
ST Employee

On my side, the code :

void part3(void) {

SIUL2.GPDO[88].R = 0;

SIUL2.MSCR_IO[88].R = ((2 << 24) | (1 << 23));

SIUL2.GPDO[89].R = 0;

SIUL2.MSCR_IO[89].R = ((2 << 24) | (1 << 23));

}

is compiled with quite compatible assembly between GCC:

part3:

.LFB5:

e_lis %r7,0xf7fc

se_li %r5,0

e_lis %r6,0x280

e_stb %r5,4952(%r7)

e_stw %r6,928(%r7)

e_stb %r5,4953(%r7)

e_stw %r6,932(%r7)

se_blr

and with GHS:

part3:

#   .bf

.LDW41:

e_lis r11, 63484

e_li r9, 0

e_lis r0, 640

e_lis r12, 63484

e_stb r9, 4952(r11)

e_lis r10, 63484

e_stw r0, 928(r12)

e_stb r9, 4953(r10)

e_stw r0, 932(r11)

#   .ef

.LDW51:

se_blr

Remark: This issue have no link with our product: SPC5Studio.

If you have more concerns about GHS compiler, please contact GHS.

Best regards,

-Olivier

Okay, thank you for your help. Maybe I asked this question wrongly. I have one more question. In the debug session I can't modify SIUL2 registers if I use the code which is compiled by GHS but I can modify MC_ME registers, this is same in SFRs window. If I download the code compiled by GNU in the debug session I can access and modify both MC_ME and SIUL2 registers on the code or SFRs window. Can any code cause this?

Hello,

Sorry, when I answered about your "GHS compilation issue" yesterday, I did not see this additional question. This explains why I misunderstood your question. ;-(

Please let me check.

-Olivier

do you have same version of windows GHS compiler in your install_log file ?

Installing "Compiler 2016.5.4 and Probe 5.4.4 for Power Architecture" to "C:\ghs\comp_201654"

with this version, it is producing the assembly code for MSR in my binary (same than GCC)

This is mine: Installing "Compiler 2019.1.4 and Probe 5.6.4 for Power Architecture" to "C:\ghs\comp_201914". Maybe I couldnt explain again. Let me summarize my problem. I have a task about adding new features to existing project which is on Eclipse and compiled by GHS compiler. I dont want to damage or get affected by existing project so I open an empty SPC5 project, write code, try everything and if it works I applied same code to existing project. I started with LED toggling, uploaded hex file and it worked. I copied and pasted same code to existing project and commented out other code. When I upload the hex file I saw it cant modify SIUL2 registers. I thought code is same so its because of compiler. But then I realize startup file of existing project doesnt have code to set MSR register, other things are almost identical, maybe setting MSR is must and it causes the error. Thats why I asked second question.

ODOUV.1
ST Employee

I have no idea.

If you want to test your hypothesis, you could go back to use GCC again but removing the configuration of MSR in boot.s to check if you reproduce the same behavior with GCC.

BRs,

-Olivier