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

Initializing Memory

How do we initialize the XDATA memory with dummy data (e.g. 0xDEADBEEF)?

By default all the memory is initialized to 0x00 during debugging (in the IDE). When you burn your firmware on the controller, the memory holds random values. To be able to detect uninitialized variables, I'd like to initialize the XDATA memory space to a predefined (non-zero) value.

Note that I don't want to overwrite the global static variables (i.e. those that are rightly initialized to a value). E.g.
static unsigned char foo = 0x00.

I guess what I want must be done in INIT.A51, prior to initializing the static variables. Any idea how? Samples welcomed!

  • Have you looked at the comments in startup.a51 ?

  • As Andy says, STARTUP.A51 initializes memory. It's attempting to fulfill the requirements of the C language spec that uninitialized variables have value 0. If you change the fill pattern, then programmers for your system need to be aware that they cannot rely on the C runtime init'ing their variables to zero for them.

    You also might consider avoiding initialized constant globals. INIT.A51 has to copy the values from non-volatile code space to xdata/data space. So, you have two copies of your values, which can be a waste of memory space. You can declare the variable as code and just read the value straight from code space.

  • Hi guys

    Thanks for the tip. Indeed, the snippet of code below seems to be doing what you indicated:

    IF XDATALEN <> 0 MOV DPTR,#XDATASTART MOV R7,#LOW (XDATALEN) IF (LOW (XDATALEN)) <> 0 MOV R6,#(HIGH (XDATALEN)) +1 ELSE MOV R6,#HIGH (XDATALEN) ENDIF CLR A
    XDATALOOP: MOVX @DPTR,A INC DPTR DJNZ R7,XDATALOOP DJNZ R6,XDATALOOP

    In my case, XDATALEN was set to zero.

  • Please read the instructions on how to post source code:
    www.danlhenry.com/.../keil_code.png

    Note that TABs don't work (well) - use spaces instead,

    and don't forget to check it in the 'Preview'...