Forum : ST7/STM8
Original Post
Post Information | Post |
---|---|
October 20, 2009 - 3:01pm
|
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; } } -- |
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
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.
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
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
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: