scater file problems

Hi
I am using uvision to develop code for LPC1768. my code is not small but I am sure I have lots of unused SRAM and I have assigned enough heap and stack

But I have a problem. Some of my variables get values other than what they should have. For example a variable that I set it 1 in timer interrupt (and define it volatile when declaring it), is having 0 value when is referred to in code, etc

When these problems happen, I define the variable in a specific address, like this

unsigned char Flash_write_values[512] __attribute__((at(RAM_BaseAddress + 0x5000)));
unsigned char Flash_Data[512] __attribute__((at(RAM_BaseAddress + 0x5200)));
volatile unsigned char  SMS_QueueActive __attribute__((at(RAM_BaseAddress + 0x5A04)));

Now that my code is getting bigger, this problem is occurring more frequently.
Maybe I should define all my variables in specific addresses. What is your opinion?

I started studying linker manuals to learn how to create scatter files, but it seems the manuals are too large and not enough simple to work/start with

How do you suggest me to proceed?
Thanks in advance

Parents
  • You can have your variables in a specific source file (without any absolute addresses specified) and have the full source file store the variables in a different memory region by using the scatter file.

    Absolute addresses is best when you need to map a specific variable to overlap specific hardware - it really shouldn't be used to make the linker's task into your task. Remember that if you change the size of one of your arrays, then you suddenly have to recompute a whole lot of absolute addresses. Bad, bad, bad.

    But another thing - are you remembering to make your variables volatile, when they are modified by an ISR but read by the main loop? It really is a must, to inform the compiler that there are asynchronous changes possible to the variable values. Else the compiler will generate code that assumes it knows all places where the variable gets changed, so the code may cache old values of the variable in registers.

Reply
  • You can have your variables in a specific source file (without any absolute addresses specified) and have the full source file store the variables in a different memory region by using the scatter file.

    Absolute addresses is best when you need to map a specific variable to overlap specific hardware - it really shouldn't be used to make the linker's task into your task. Remember that if you change the size of one of your arrays, then you suddenly have to recompute a whole lot of absolute addresses. Bad, bad, bad.

    But another thing - are you remembering to make your variables volatile, when they are modified by an ISR but read by the main loop? It really is a must, to inform the compiler that there are asynchronous changes possible to the variable values. Else the compiler will generate code that assumes it knows all places where the variable gets changed, so the code may cache old values of the variable in registers.

Children
More questions in this forum