Local variable declared over global variable

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

Local variable declared over global variable

1,391 次查看
szempy
Contributor II

I am using an LPC1756 microcontroller with the latest MCUXpresso.

I did encounter a problem that my global variables are overwritten by local variables.

How can this happen?

pastedImage_1.jpg

标签 (1)
0 项奖励
回复
3 回复数

1,275 次查看
xiangjun_rong
NXP TechSupport
NXP TechSupport

Hi, Isvan,

Frankly speaking, I have not seen which global variable is overwritten by local variable from the screenshot you gave, can you clarify which global variable is overwritten by which local variable?

Generally, the local variables are saved in stack, the global variables are saved in a specific location, if the global variables are overwritten by stack unexpectedly, it means that the stack size is too small, you can redefine the stack size in the linker file, for example  _StackSize = 0x2000;

Hope it can help you.

BR

XiangJun Rong

0 项奖励
回复

1,275 次查看
szempy
Contributor II

If you check the left side of the screenshot in the expression i have put in the global variables from the upper file and the local variables are in the bottom file.

The global variable rfile is at address 0x10003974 has size of 40 and the local variable fs is placed at the address 0x1000398c so it is declared over the global variable.

I have checked in the Settings -> MCU Linker -> Managed Linker Script -> Heap and Stack placement was set to LPCXpresso Style because this project is an old one and i have started to develop it in LPCXpresso, so i have changed it to MCUXpresso Style i hope that one helps.

But i have reduced some buffers and the problem was gone.

0 项奖励
回复

1,275 次查看
szempy
Contributor II

I suppose i am using to much memory and that's why this is happening:

text        data bss     dec       hex
129736  916 13880 144532 23494

So a total of data + bss = 916 + 13880 = 14796 so that means there is only 1588 bytes left in the RAM.

0 项奖励
回复