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.

Function pass by value incorrect giving incorrect excecution

Other Parts Discussed in Thread: MSP430F5438

Using Code Composer Studio, version 4.2.0, with a MSP430 USB-Debug-Interface box and MSP430F5438.

See attached screen captures.  variable Register is 0x0001 in screen capture 1.  Step into the function, Register is 0x1C20.  Should be 0x0001.  Then the code execution is incorrect and the value passed into the function is incorrect.

1157.Screens.zip

  • I've tried 2 workarounds and neither work.

    1. removed keyword register from the function header, so tried pass by variable on stack.  Same prob.

    2. Changed if (IsSysRegister(Register)) to if (Register < SYS_END) - which is what's inside the function IsSysRegister(). Attached screen capture shows before and after running stepping over this line of code.  The debugger completely looses it - gone walkabout or awol whichever you refer.

    3364.screens.zip

    Importantly, my version 4.2.0 installation has been modified to fix a mirror breakpoints problem.  The fix was supplied by desouza to fix item 1 in this thread -  http://e2e.ti.com/support/development_tools/code_composer_studio/f/81/p/55744/266590.aspx.  The fix replaces the files, HIL.dll and MSP430.dll in the ccsv4\DebugServer\drivers directory with new ones.

    Can anyone suggest a workaround?

  • It is a minor issue, but I wanted to mention I filed a bug report for the issue where CCS displays "Unknown Register ID" in the watch window for variables that have been placed in a register. This is filed as SDSCM00038624. This problem may occur when the register is of a different size than the variable stored there. These MSP registers are 20-bits which does not match the size of the stored variable.

  • I find this statement worrisome:

    Register = *((uint *)PtrData);

    Are you sure that is OK?  What is the type of PtrData?  Is it OK to cast that to a pointer to a uint?  Is the address in Ptrdata aligned on a 16-bit word boundary?  Are you building with large model, and if so, what difference might that make?  The Data Type Storage section of the MSP430 compiler manual could help you work that out.  See http://www.ti.com/lit/pdf/slau132 .

    Thanks and regards,

    -George

  • Andy, thank you for the update and filing a bug report.  It may look like a minor issue but it has major consequences - for me, it causes incorrect program execution which is a major issue.

    George,
    To fill in the gaps, missing is:
      typedef unsigned char uchar;
      typedef unsigned int uint;
      register uchar *PtrData;
      register uint Register;
    I see no problem with the line below as long as PtrData is guaranteed word aligned and in this case it follows an global array, uchar TmpBuffer[], so it does no cross a memory block boundary.
    Register = *((uint *)PtrData);
    Been there, done that many times in the past.... that is where I or other programmers don't make sure PtrData is word aligned.
    Yes, I am using the large model.  Again, no problem as long a PtrData is word aligned.
    Is this an ok point of view?

  • Peter, a clarification on my post. The minor issue I was referring to is CCS displaying "Unknown Register ID" in the locals/expressions view. It should be providing the register in which the variable is stored. This message does not impact the target side. The main issue is as you reported. Incorrect execution is certainly a major problem.

  • On a related topic pass by value for 'register unsigned long' does not work.  In the Local window the value is displayed incorrectly.  This was reported in CCE v3 in July this year and does not appear to be fixed in version 4.2.0.  See item 1 in this thread
    "3 bugs in Code Composer - register unsigned long and changing global variable type"
    http://e2e.ti.com/support/microcontrollers/msp43016-bit_ultra-low_power_mcus/f/166/p/56096/206329.aspx

    The attached screen capture from version 4.2.0 shows an example in the Local Window:
    Addr is incorrect - register unsigned long.  0x00000.  Should be 0x10000
    Addr2 is correct - unsigned long

    0247.screen1.zip

  • Peter,

    Could you provide a test case that can be used to duplicate the original issue with register value being passed incorrectly? If you do not wish to attach it here, you can send it to me via private message.

  • Aarti, how about a copy of the .out file?

    How do I send you a private message?  Sorry, can't find that option on this thread or on your profile page.

  • Peter,

    I sent you a friend request. After you accept, we will be able to exchange private messages.