Topic : Incorrect initialization

Forum : ST7/STM8

Original Post
Post Information Post
October 20, 2009 - 3:01pm
Guest

Repost. I put this in the ARM section of the forum by mistake.

In the following code b7 is set to 0, and b1 is set to 1 during initialization.

bit b1,b2,b3,b4,b5,b6;
bit b7=1;
bit b8, b9, b10;

int main(void)
{

    if (b7)
    {
        b8 = 1;
    }

}

--
Blasio

Replies
Post Information Post
+1
0
-1
October 22, 2009 - 10:58am
Raisonance Support Team

Hi Blasio,

We were not able to reproduce the problem in our Labs.
Can you post the .lst file produced by the compiler, so that we can investigate the problem?

Thanks,
Bruno

+1
0
-1
October 22, 2009 - 12:25pm
Guest

I'm pasting the .lst below. The issue does not show in it however, as the problem is in the startup code rather than in the main() routine. I'm also going to zip up a test project and send it to your support email address.

RCSTM8 COMPILER V2.25.09.238,  MAIN               10/22/09  12:11:11

QCW(0x00183F20)

RCSTM8 COMPILER V2.25.09.238, COMPILATION OF MODULE MAIN      
OBJECT MODULE PLACED IN C:\Documents and Settings\blasio muscat\Desktop\Test\Main.obj
COMPILER INVOKED BY: QUIET GENERATEDEPFILE CODE DB OJ(C:\Documents and Settings\blasio muscat\Desktop\Test\Main.obj) PR(C:\Documents and Settings\blasio muscat\Desktop\Test\Main.lst) PIN(C:\Program Files\Raisonance\Ride\Inc;C:\Program Files\Raisonance\Ride\Inc\ST7) ST7 DGC(DATA) DLC(PAGE0) O(3,SIZE) NOINITSTATICVAR SMALLOBJECT ET(INT) 

stmt level    source
   1          bit b1,b2,b3,b4,b5,b6;
   2          bit b7=1;
   3          bit b8, b9, b10;
   4          
   5          int main(void)
   6          {
   7   1      
   8   1          if (b7)
   9   1          {
  10   2              b8 = 1;
  11   2          }
  12   1      
  13   1      }
*** WARNING C096 IN LINE 13 OF C:\Documents and Settings\blasio muscat\Desktop\Test\Main.c : Function 'main' should return a value

RCSTM8 COMPILER V2.25.09.238
ASSEMBLY LISTING OF GENERATED OBJECT CODE

              ; FUNCTION main (BEGIN)
              ; SOURCE LINE # 8 
0000 0D0002     F                      BTJF   b7,?EPILOG_0000
              ; SOURCE LINE # 10 
0003 1E00       F                      BSET   b8
0005         ?EPILOG_0000:
0005 81                                RET    

              ; FUNCTION main (END)

RCSTM8 COMPILER V2.25.09.238


MODULE INFORMATION:   STATIC OVERLAYABLE
   CODE SIZE        =      6    ----
   CONSTANT SIZE    =      1    ----
   DATA SIZE        =   ----    ----
   PAGE0 SIZE       =   ----    ----
   BIT SIZE         =     10    ----
END OF MODULE INFORMATION.

RCSTM8 COMPILATION COMPLETE.  1 WARNING,  0 ERROR
+1
0
-1
October 22, 2009 - 1:58pm
Raisonance Support Team

Blasio,

Indeed this assembly code looks good to me.

Your project uses the NOINITSTATICVAR compiler directive. This means that global variables (including bit) are NOT initialized unless explicitly done through an assignement in your code.

So declaring
bit b8, b9, b10;
does not perform any initilization on b8, b9 and b10, they have random values upon startup.

If you want them to be automatically initialized to 0, just use the INITSTATICVAR compiler directove (warning: this has a small cost on application startup)

Another way to handle it is to write:
bit b8 = 0, b9 = 0, b10 = 0;

Which ensure that these variables are always initialized.

Let me know if you still have issues.
Regards,
Bruno

+1
0
-1
October 22, 2009 - 2:29pm
Guest

Hello Bruno,

I understand about the NOINITSTATICVAR, but that's not what I'm talking about.

- In the example code I'm setting declaring b7 with an explicit initialization to 1.
- In the main() routine, b7 is 0 as soon as execution starts. It should be 1.

All other bit variables will be in an unknown state, but b7 should be set correctly.

Regards,
Blasio

+1
0
-1
October 22, 2009 - 5:31pm
Guest

Hi

As discussed by email with Blasio

This is indeed a bug in the data initialization, the linker inverts the bit numbers for bit variables (initializes bit0 instead of bit7, bit1 instead of bit6 etc).

We will fix this in the next release of RKit-STM8.

A workaround to the problem is NOT to initialize the bit variables, and perform the assignment "by hand" in your main as follows:

bit b1,b2,b3,b4,b5,b6;
bit b7;
bit b8, b9, b10;

void main(void)
{
    b1=0;
    b2=0;
    b3=0;
    b4=0;
    b5=0;
    b6=0;
    b7=1;
    b8=0;
    b9=0;
    b10=0;
}