Topic : Bad ZeroData routine generated when using static variables

Forum : ST7/STM8

Original Post
Post Information Post
July 24, 2009 - 11:37am
Guest

I've encountered an issue where the ZeroData routine used during startup will overwrite the whole ST7 stack, causing a crash when it tries to return. The issue seems to be related to initialising static variables to 0. The following code triggers the bug:

char page0 a=0;
char page0 dummy[122];
char b=0;

void main(void)
{

b = a++; // This is not important, just used it for a breakpoint
while(1);
}

void foo(void)
{
static char page0 bar=0;

}

I believe I'm using the latest software version, this is what I have in About Ride7:

Ride7 version 7.20.09.0162
RKit-STM8 version 2.20.09.161

At this point I'm just using global variables instead of statics.

--
Blasio

Replies
Post Information Post
+1
0
-1
July 24, 2009 - 1:57pm
Guest

Hi

Can you let us know your target.
When I try your code with an ST7 I get a stack over flow error.
WHen does the crash appear?

Regards,
Matloub

+1
0
-1
July 24, 2009 - 2:26pm
Guest

I'm using ST72361AR6 as a target, but I think it will happen for any ST7 target. The crash is within the startup code generated by the compiler. Execution never reaches main().

+1
0
-1
July 30, 2009 - 11:17am
Raisonance Support Team

I tried your little sample with your chip, but the link fails due to an address space overflow on ?ZD0?MAIN

Then I switched Default global memory class to Data and the sample links well and I'm able to debug in main.

I'm using the latest version (2.22.09.0203), but we haven't fixed anything in the ST7 startup.

Can you provided us more information or better a zipped project to:

Regards,

Stéphane

+1
0
-1
July 30, 2009 - 11:35am
Guest

I've emailed the whole test project to .

+1
0
-1
July 30, 2009 - 12:24pm
Guest

I just downloaded the latest toolkit, and the problem is still there.

Maybe this will help you to trace the problem:

Normally ZeroData() loads BX with the start of the area to Zero, and CX with the length of the area. For my test code it loads BX with 0x00FE, and CX with 0x0103, which results in the stack being overwritten.

NOTE: The test code "works" if you exclude startup.asm from the project, as then ZeroData() is inlined, and there's nothing on the stack to damage.

+1
0
-1
August 5, 2009 - 8:16am
Guest

The problem was within the linker of the latest release. A patch is available on the download page (for both a RLink issue with the verify command, and this linker issue).