Hi ,
I am using ARM Cortex M4 . When I compile my code I get "No space in Execution region with .ANY selector matching section .const data .When I decrease the code size I am able to compile the code properly.I think I am overusing the data section which in my controller is 32KB.
I want to know where are all local variables stored in ARM KEIL IDE.Is it stored in Stack dynamically or stored in DATA memory Statically .
Thanks in advance
Regards, Dhanush
I think you are deviating from the topic . I wish to know how is "LOCAL VARIABLES" i.e. variables declared inside a function , causing memory overuse problems.I think "LOCAL VARIABLES must be stored in STACK runtime , but I think I am wrong in case of KEIL IDE.
So long story short , I wish to know where are "LOCAL VARIABLES stored in the memory section And why is it increasing my memory requirement .
Remember that when you are decreasing your code size, you may also reduce some text strings - maybe part of printouts or data for some display.
A text string is a const data variable in the compilers view. So even if it's used inside a function, the text has to be stored in the flash. Depending on how your code is written, the compiler may be able to use the string directly from flash. Or it may be copied into a RAM-based variable (global or on the stack depending on the used variable scope).
So:
mon_printf("Inside function xx()");
will require the character array "Inside function xx()\0" to be stored in the flash. And the compiler will consider it const data, i.e. you aren't allowed to modify it.
If you instead have:
void my_function() { char my_local_array[] = {'a','b','c','d','e','f'}; ... }
Then the compiler is free to decide if it will initialize this local variable "my_local_array[]" using explicit procesor instructions, or if the compiler will instead create a secret const data object (it could decide to store this as "text" or as "const data" or whatever it wants to - but it has to originate in flash) allowing the function to start by doing something similar to a memcpy() to initialize that variable.