This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Scatter file for Cortex-M0 LPC11xx

Hi everybody,

My question is regarding a Cortex-M0 NXP's LPC1114/301.

I am having trouble with the initialization sections that sets the initial values of variables. For example:

int x = 20;

int main(void)
{ if(x==20) do_something();

.....

}

When I run this code, the value of x is undefined and has actually a random value. I know I have to copy the etext section to edata, and also initialize the bss section to 0. But how do I do this in Keil with a scatter file + startup file in assembler? The default startup file from Keil for the LCP1114 doesn't do it...

Thanks in advance,

R.

  • Could this be just an Optimisation issue?

  • No, it doesn't enter the "if" statement. Do_something() is never executed. It was just an illustration example of the problem. I actually check the x value within the debugger, which reveals that x never holds the given value in its declaration.

    R.

  • Checking variables in the debugger is not a safe way to verify that the startup file functions. The compiler may remove the variable and the "if" statement and instead generate code to directly call the function, if the compiler is able to figure out that the variable may never take another value than 20 at that point in the code.

    Are you doing something different compared to what Keil is doing in their example programs? I don't think Keil have shipped any startup files that doesn't have support for initialization of variables since that is a standard function required by the C compiler.

    In the target configuration tab for the project, the R/W memory regions have a checkbox "NoInit" - have you checked this checkbox? Or have you done something creative with your scatter file?

  • No, it is just an example. It's not the real program, but I was trying to expose my problem in a simple way.

    I have looked into the project configuration and the NoInit box is not checked.

    The startup.s file I'm using is the one that uVision generates automatically when you choose the device model.
    I haven't changed nothing from the original scatter file.

    Thanks for the help anyway.

    R.

  • -> I know I have to copy the etext section to edata, and also initialize the bss section to 0. But how do I do this in Keil with a scatter file + startup file in assembler? <-

    (I think/guess) You don't have to do anything, it is done by KEIL's __main automagically.

    I don't know much about this, but maybe:

    http://www.keil.com/support/man/docs/armlib/armlib_cihfddfg.htm


    How C and C++ programs use the library functions

    This section describes:

    * specific library functions that are used to initialize the execution environment and application

    * library exit functions

    * target-dependent library functions that the application itself might call during its execution.

  • > (I think/guess) You don't have to do anything, it is done by KEIL's __main automagically.

    Yeah, that was it!
    I remember getting a "main not found" error and I changed the startup assembler code to call "main" directly, instead of the original "__main".
    But now, for some reason, I am not getting this error, and as a result, the variable initialization is working fine, as it should be.

    Thanks a lot!

    R.

  • Oops - you forgot to mention that you changed the startup code...