How to turn off code optimization

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How to turn off code optimization

1,671 Views
HarryHirn
Contributor I

hi

 

codewarrior tries to drive me crazy... and it does this job quite good......

 

somewhere in my code i want to toggle a pin to trigger my peripherals to do something...

 

 

DUT_WAKEN_ClrVal();DUT_WAKEN_SetVal();

 

 

i declared a been for a single pin DUT_WAKEN.

the whole day this worked and i was able to step through the debigger and he was executing this and measuring at the hardware showed the toggle... up to now.

 

i did just small modifications on some code sorting but now debugger skips the ClrVal() and at the pins of the µC the pin keeps high.

 

i found codewarrior shortening my code here and there disabling to step to some portion of code but now it strips even the funtional parts...

 

how can i turn off the whole optimization and shortening of code?

 

my hc12 compiler options out of the box: -Cf -CPUHCS12 -Mb -TD4LD4LLD4

 

i cant really waste my last weeks of diploma thesis with trying to teach codewarrior to keep my code...

 

thx for help

Labels (1)
Tags (1)
0 Kudos
7 Replies

798 Views
BlackNight
NXP Employee
NXP Employee

Hi,

Could you share how you have declared DUT_WAKEN_ClrVal()?

Have you declared your port with 'volatile'?

'volatile' tells the compiler not to optimize such things.

 

BK

0 Kudos

798 Views
HarryHirn
Contributor I

hi

 

sorry for taking so long to answer but we were off to lunch :smileywink:

 

the function is a processor expert bean for general 1bit i/o

i did nothing than enabling the method creation of ClrVal und SetVal.

that leads to the auto generated code

 

 

#define DUT_WAKEN_ClrVal() ( \    (void)clrReg8Bits(PORTB, 8)        /* BIT3=0 */ \  )#define DUT_WAKEN_SetVal() ( \    (void)setReg8Bits(PORTB, 8)        /* BIT3=1 */ \  )

 

 

my function is a bit long because it proofs several cases...

ill try to short out repeated parts

 

 

void DUT_autotest(void){    uint8_t temp = 0;  uint8_t temp2 = 0;  errorcode1 = 0;                  // Reset error code (volatile)  errorcode2 = 0;          /***** Flag Test *****/      DUT_power_mode(GOTOSLEEP);  FUNCTIONS_delay(10);  errorcode2 |= ((~DUT_RXD_GetVal() & 1) << 6);  errorcode2 |= ((~DUT_ERRN_GetVal() & 1) << 7);  DUT_WAKEN_ClrVal();  DUT_WAKEN_SetVal();  FUNCTIONS_delay(10);  errorcode2 |= (DUT_RXD_GetVal() << 6);  errorcode2 |= (DUT_ERRN_GetVal() << 7);            MUX_disconnect_all();           // Disconnect the whole DUT. It becomes unconnected and unpowered.}

 

i deleted repeated tests because they all look like this for different power modes.

 

errorcode is extern volatile.

 

so the only thing this should do is read the two pins, generate a wake signla by toggling WAKEN and check that pins again...

 

dont know if this helps but in my opinion there is nothing to shorten for the compiler, but i am not a specialist in compilers... :smileyhappy:

 

 

 

0 Kudos

798 Views
BlackNight
NXP Employee
NXP Employee

Hi,

PORTB should be volatile, so this could not be the problem.

Could you disassemble the code of DUT_autotest() and post it? Then we should see what really happens on the target.

 

BK

0 Kudos

798 Views
HarryHirn
Contributor I

hmmm, maybe if you tell me how to do that :smileysurprised:

i found out that i can rightclick an disassemble, but where and how can i see that disassembled code?

 

ok i was right, but codewarrior tried to hide the generated file from me :smileywink:

 

i didnt want to post 1100 lines so i looked for the corresponding lines:

 

 

522:      /***** Flag Test *****/  523:      DUT_connect_functional();  012c 4a000000     [7]     CALL  DUT_connect_functional,PAGE(DUT_connect_functional)  524:      DUT_power_mode(NORMAL);      0130 160000       [4]     JSR   DUT_autotest:0x0304  525:        526:      // GoToSleep  527:      DUT_power_mode(GOTOSLEEP);  0133 c602         [1]     LDAB  #2  0135 160000       [4]     JSR   DUT_autotest:0x0336  528:      FUNCTIONS_delay(10);  0138 c60a         [1]     LDAB  #10  013a 160000       [4]     JSR   DUT_autotest:0x0311  529:      errorcode2 |= ((~DUT_RXD_GetVal() & 1) << 6);  013d 4a000000     [7]     CALL  DUT_RXD_GetVal,PAGE(DUT_RXD_GetVal)  0141 51           [1]     COMB    0142 c401         [1]     ANDB  #1  0144 87           [1]     CLRA    0145 cd0040       [2]     LDY   #64  0148 13           [3]     EMUL    0149 160000       [4]     JSR   DUT_autotest:0x02af  530:      errorcode2 |= ((~DUT_ERRN_GetVal() & 1) << 7);  014c 160000       [4]     JSR   DUT_autotest:0x0309  014f 87           [1]     CLRA    0150 cd0080       [2]     LDY   #128  0153 13           [3]     EMUL    0154 160000       [4]     JSR   DUT_autotest:0x02af  531:      DUT_WAKEN_ClrVal();          0157 160000       [4]     JSR   DUT_autotest:0x032f  532:      DUT_WAKEN_SetVal();  533:      FUNCTIONS_delay(10);  015a 160000       [4]     JSR   DUT_autotest:0x02d2  534:      errorcode2 |= (DUT_RXD_GetVal() << 6);  015d ce0040       [2]     LDX   #64  0160 b750         [1]     TFR   X,A  0162 12           [1]     MUL     0163 160000       [4]     JSR   DUT_autotest:0x02af  535:      errorcode2 |= (DUT_ERRN_GetVal() << 7);  0166 d600         [3]     LDAB  _PORTAB:1  0168 c401         [1]     ANDB  #1  016a cd0080       [2]     LDY   #128  016d b760         [1]     TFR   Y,A  016f 12           [1]     MUL     0170 160000       [4]     JSR   DUT_autotest:0x02af  536:        537:      // Standby/Sleep

 

in that file i looked for the adress of that 

JSR   DUT_autotest:0x02af

and there it says

 

 

02af fa0000       [3]     ORAB  errorcode2:1
...
0309 d600         [3]     LDAB  _PORTAB:1

 

if i understand that file correctly :smileywink:

 

 

btw is there some kind of assembler code listing for the MC9S12DP ?

0 Kudos

798 Views
CompilerGuru
NXP Employee
NXP Employee

 

  0154 160000       [4]     JSR   DUT_autotest:0x02af  531:      DUT_WAKEN_ClrVal();          0157 160000       [4]     JSR   DUT_autotest:0x032f  532:      DUT_WAKEN_SetVal();

 Those JSR's to the end of the functions probably contain the code to clear/set the bit. However as far as I remember source stepping does bypass them, so either assembly step to see the toggle happening or switch that optimization off with -onf. Code will probably get significantly bigger.

My current guess is that the code still does what it should, but "just" source stepping does not behave as expected.

 

Daniel

 

 

0 Kudos

798 Views
HarryHirn
Contributor I

ok i figured out how i can make the compiler notice that i want to have that function :smileywink:

 

when i execute my self written delay function between them it works

 

 

DUT_WAKEN_ClrVal();FUNCTIONS_delay(10);        DUT_WAKEN_SetVal();

 

 

and i can step the debugger through both functions.

 

i only need the delay function between the Clr and SetVal functions once.

all of the calls, even if they are called like before, will execute correct

 

 

DUT_WAKEN_ClrVal();        DUT_WAKEN_SetVal();

 

 

 

if i take away that delay function the compiler erases all of the ClrVal() function...

 

that or other ways (volatile) cant be the trick to make the compiler work as expected...

 

(or is it my misunderstanding of c programming)

0 Kudos

799 Views
CrasyCat
Specialist III

Hello

 

Here it would help to see the whole code of the function where DUT_WAKEN is invoked.

There must be a reason why the compiler skips out the invocation.

 

Also did you take a look at the preprocessor listing for this function?

 

CrasyCat

0 Kudos