This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

IAR c code question



I define a 2 x 64 buffer in  __xdata. I fill it with 0xAA  Then in debug I look at the contents of xdata memory  for my  pattern which I do not see.
.
Using a watch box on audioOut[0][i] I see the data is somewhat random which is why there is no pattern in memory..

What am I I missing? Why is the data random? 

IAR Workbench  -   The optimizer is off.  i increments correctly

Code summary:

#define AF_BUF_SIZE 0x40
unsigned short   __xdata     audioOut [2] [AF_BUF_SIZE];

int main(void)

    for (i=0; i < AF_BUF_SIZE; i++)
    {
          audioOut[0][i] = audioOut[1][i]   = 0xAA;      // I tried  = 0 in place of 0xAA, it did not work either
    }

  • Are you talking about MSP430? Are there any external memory? Which chip?

  • what does __xdata do?

  • Hi,

    I assume __xdata is your own data type, isn't it? Can you pls provide some more details on this? Would you pls try this:

    for (i=0; i < AF_BUF_SIZE; i++)
    {
      audioOut[0][i] = 0xAA;
      audioOut[1][i] = 0xAA;
    }

    Rgds
    G**buster

  • 1.) {  audioOut[0][i]   = 0xAA;
             audioOut[1][i]   = 0xAA;  }

    or just { audioOut[0][i] = 0xAA; } gives the same result

    2.)  __xdata is a keyword in IAR mapping the storage into slow RAM and not code, SFR, or fast RAM space.

    3.) There is no external memory, I wish it had the capability.

    4.) The device is a Ti SOC with a 8051 core (Yes this is the MSP430 forum but it is under microcontrollers, it is the best fit, and I had hoped this was a generic c question but looking at the 430 architecture I can see it's memory map is very different.)

    So, I write to a block of RAM and get mostly* random data, what gives??

    * If I write 64 words of 0x00 I see about 30 0x00 in memory and 34 apparently random values intersparsed in a random pattern. Their location and value is different each time I run the code.

  • Hi H Stewart,

    I'm sorry, but I have no knowledge on C8051 core and/or toolchain.

    Maybe somebody help is able to help you.

    Kind regards
    G**buster

  • You might try posting/looking through some LPRF threads since some of the CC devices are 8051 Core...

  • Thanks, I posted there with no response, its not really about raw c coding. I need to find an IAR / MCU forum, no luck on that front yet, maybe I can put on my SiLabs disguise..... they have an active forum for 8051s.

  • Hi.

    Just tried this and it works like a charm.
    Where in the xdata is your audioOut buffer located?

    Kjetil

  • What is really missing is an appropriate configuration of IAR Embedded Workbench.

    Minimum configuration for a CC1110 device:

              1) General Options -> Target -> Derivative information -> Derivative -> CC1110

              2) Linker -> list -> check Generate linker listing

              3) Linker -> Config -> Linker command file -> check Override default and choose lnk51ew_cc1110.xcl

              4) Debugger ->  Chipcon

    Hope this helps

    Priquas Polymath

  • Thank you both for the help. 

    Kjetil - Due to the random data it is impossible to tell where the data is if it is there at all. There is a block in the range of F000-F1B0 that is nearly the right size (4 x 64 ) and place. Notice the distribution of 0x00 which I'm current setting the arrays to. 

    Priquas - I had IAR set up correctly except  [Linker -> list -> check Generate linker listing] was not checked. I'm not sure where the list is located.

    My next question is when is the memory data valid?  It appears to update when I do a reset in debug. When I run to cursor or a break point right after I fill the array I do not see change.

    The watch boxes for the arrays all show values after a reset but only array1 [0][i] and array2 [0] [i] show values after running to cursor whereas array1 [1][i] and array2 [1] [i] both show error.

    I believe the compilier should handle this with the --xdata key word. The alternative would be to formally create a pointer to a specific address.

  • Kjetil

    You said you tried it and it worked.   What steps did you use to "see" the data and where was it???

     

    Thanks

     

    Hamilton

  • Hi.

    Took one the SoC example projects located here:
    http://focus.ti.com/docs/prod/folders/print/cc2510f32.html#toolssoftware

    Then added your code:

    #define AF_BUF_SIZE 0x40
    unsigned short   __xdata   audioOut [2] [AF_BUF_SIZE];

    int main(void){

        for (unsigned char i=0; i < AF_BUF_SIZE; i++)
        {
              audioOut[0][i] = audioOut[1][i]   = 0xAA;      // I tried  = 0 in place of 0xAA, it did not work either
        }
        while(1);
    }   

    Added a watch to the audioOut buffer and it's located at xdata 0xF000. Updated values can be seen either in the watch or in the memory view.

  • Thanks Kjetil.   Knowing I had the code right was a big help. It caused me to search hard for an error.  Found it, I used one variable to define buffer size and another in the loop in the actual code ( I got my summary right).

    Priquas pointed out the need for “Linker command file” which mapped xdata start to F000, also a big help.