Local variable overlaps part of global variable space

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 
已解决

Local variable overlaps part of global variable space

跳至解决方案
720 次查看
louislee
Contributor I

Hi,

 

It's first time I contact S08AW32 w/ codewarrior 10.6. The development tool is Multilink Universal. I create several files and many function calls.

 

In file Main.c:

void main(void)

{

     Record_AddUser();

}

 

In file Record.c:

typedef struct {

     byte Template[498];

     // other members

} tUserData;

 

void Record_AddUser(void)

{

     tUserData sUserData;

 

     // do something...

    GetTemplate(gbyTemplate);

     memcpy(sUserData.Template, gbyTemplate, 498);     // <------ overlapping !!!!

}

 

In file FP.c: (provided by h/w module vendor)

byte gbyTemplate[498];     // global variable

 

void GetTemplate(byte* pBuf)

{

     byte Buf[498];

 

     // do somethins to get Template, and put it into Buf.

     memcpy(pBuf, Buf, 498);

}

 

 

After calling function GetTemplate(gbyTemplate), value of many other variables are changed. And then, I find something wrong. The structure sUserData is allocated at 0x0133, and gbyTemplate is allocated at 0x00A5. Can anyone help? Thank you!!

标签 (1)
0 项奖励
回复
1 解答
497 次查看
kef2
Senior Contributor V

Hi,

function scope non-static variables are allocated on stack. Default stack size in CW generated S08 projects is about 0x80 bytes. This is much less than your Buf size plus sUserData size. Stack size is specified in linker *.prm file. Don't forget though that you have only 2k of RAM for all purposes.

Edward

在原帖中查看解决方案

0 项奖励
回复
2 回复数
498 次查看
kef2
Senior Contributor V

Hi,

function scope non-static variables are allocated on stack. Default stack size in CW generated S08 projects is about 0x80 bytes. This is much less than your Buf size plus sUserData size. Stack size is specified in linker *.prm file. Don't forget though that you have only 2k of RAM for all purposes.

Edward

0 项奖励
回复
497 次查看
louislee
Contributor I

Hi Edward,

Thank you for reply soon.

Yesterday I had reallocated the stack size several times, but unfortunatelly , nothing changes. The library from module vendor is dedicated for Kinetis. Maybe I'll look for another mcu since I shouldn't modify the library for some reason. In fact, I have these code work fine in Kinetis M0+ and M4 w/ "large" RAM size.

Anyway, you are right. Thx angin!!

0 项奖励
回复