Local variable overlaps part of global variable space

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

Local variable overlaps part of global variable space

ソリューションへジャンプ
838件の閲覧回数
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 解決策
615件の閲覧回数
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 返答(返信)
616件の閲覧回数
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 件の賞賛
返信
615件の閲覧回数
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 件の賞賛
返信