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.

CCS/TMS320F28075: Error in converting to 32bit value

Part Number: TMS320F28075

Tool/software: Code Composer Studio

Hello,

I am trying to decode a serial stream and extract some 32bit values.

Here is part of my code:

#define UB_MAX_PACKET 128
.
.
.

char buffer[UB_MAX_PACKET];
.
.
.


int16 ExtractuBData()
{
.
.
.
    int32 it;
.
.
.
    it = *((int32 *)&buffer[10/2]);
.
.
.
}



As shown below in debug screen, I expected on breakpoint to have the value of 0x1e935e75 = 512974453 which is buffer[6]:buffer[5], but I have 0x5e75087f = 1584728191 which is buffer[5]:buffer[4]
The second line in Expressions window is the exact expression as it variable in first line of expression window but different results.

The CCS is V10.1.0 and CGT is V20.2.2. Code is generated with the default compiler and linker settings of Debug configuration of CCS.

With regards,
MHG

  • Mir Hossein Ghoreishi said:
    As shown below in debug screen, I expected on breakpoint to have the value of 0x1e935e75 = 512974453 which is<strong> buffer[6]:buffer[5]</strong>, but I have 0x5e75087f = 1584728191 which is <strong>buffer[5]:buffer[4]</strong>The second line in Expressions window is the exact expression as <strong>it</strong> variable in first line of expression window but different results.The CCS is V10.1.0 and CGT is V20.2.2.

    Section 7.1.7 Field/Structure Alignment of the TMS320C28x Optimizing C/C++ Compiler v20.8.0.STS User’s Guide says:

    Types with a size of 32 bits or larger are aligned on 32-bit (2 word) boundaries.

    I am not sure what happens when you cast an address which is not aligned on a 2 word boundary to an int32 *, but based upon your results it looks like the address used gets rounded down.

    Not sure if this a bug in the compiler, or the code invoking undefined behaviour. Rather than casting the address of an odd index in buffer to an int32 *, perhaps accessing the buffer as two 16-bits words, and then bit-shift and add to form one 32-bit value would avoid the issue.

  • Hello Chester,

    Thank you for your prompt reply.

    Actually the code was proted from x86 machine and I should apply this compiler restrictions.

    But I expect the same result from compiler and debugger. I expect the first two lines in Expression window show the same value.

    MHG

  • The analysis by Chester Gillon is correct.  The C28x CPU expects 32-bit memory reads and writes to be a aligned to an even 16-bit word address.  For further documentation, please search the TMS320C28x DSP CPU and Instruction Set Reference Guide for the sub-chapter titled Alignment of 32-Bit Accesses to Even Addresses.

    Mir Hossein Ghoreishi said:
    I expect the same result from compiler and debugger

    In this particular case, the debugger display is incorrect.  It does not access 32-bits of memory starting at an odd address the same way the C28x CPU does.

    Thanks and regards,

    -George

  • Hello George,

    Thank you, I just fixed my code.

    I have two suggestions:

    1) The Debugger should be fixed to give consistent results.

    2) In the above case the pointer was static and compiler could detect and warn about accessing odd address 32bit memory.

    With regards,

    MHG