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?

15 REPLIES 15

I removed that part and it is still working, anyways thank you for your help.

ODOUV.1
ST Employee

Hello,

it concludes it is not the root cause of your issue.

I wonder if you have the same definition of SIUL2 in your 2 projects ?

on SPC58EC it should be:

#define SIUL2                 (*(volatile struct SIUL2_tag *) 0xf7fc0000UL)

BRs,

-Olivier

Yes those definitions are same. As I said I commented out existing project's code and used the code above only toggling LEDs. It didn't work so I gave up commenting out their initialization and use it. I only put this part:

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));

That way let me change SIUL2 and I could toggle LEDs. I couldn't understand because assembly codes of main functions were same, so code was trying to modify that register and processor doesn't let it change. Also in debug session I couldnt change it from SFRs window. It somehow does protection or something like that.

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

I am so sorry, I didn't see it was weak function and __early_init name was like just assembly function, I couldn't imagine ST define it in .c file so I didn't even search in project. I only looked in that file and __early_init was an empty function. Thank you for making me awake to this and thank you for all replies and support.

ODOUV.1
ST Employee

Thank you for your answer.

Happy that the situation is unlocked at your side.

Best regards,

-Olivier