Local variable declared over global variable

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Local variable declared over global variable

1,389 Views
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

Labels (1)
0 Kudos
Reply
3 Replies

1,273 Views
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 Kudos
Reply

1,273 Views
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 Kudos
Reply

1,273 Views
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 Kudos
Reply