Skip to main content
kb24
Senior
April 6, 2022
Solved

GNU vs GHS

  • April 6, 2022
  • 7 replies
  • 4982 views

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?

    This topic has been closed for replies.
    Best answer by ODOUV.1

    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

    7 replies

    kb24
    kb24Author
    Senior
    April 6, 2022

    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
    April 7, 2022

    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

    ODOUV.1
    ST Employee
    April 6, 2022

    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

    kb24
    kb24Author
    Senior
    April 6, 2022

    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
    April 6, 2022

    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

    kb24
    kb24Author
    Senior
    April 6, 2022

    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?

    ODOUV.1
    ST Employee
    April 7, 2022

    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

    kb24
    kb24Author
    Senior
    April 8, 2022

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

    ODOUV.1
    ST Employee
    April 8, 2022

    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

    kb24
    kb24Author
    Senior
    April 8, 2022

    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
    ODOUV.1Best answer
    ST Employee
    April 8, 2022

    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

    kb24
    kb24Author
    Senior
    April 8, 2022

    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
    April 11, 2022

    Thank you for your answer.

    Happy that the situation is unlocked at your side.

    Best regards,

    -Olivier