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 V5.3 Problem with functions using Variable-length Argument List - C5535 Processor



Okay, so after a week looking into this I am sure this is a bug in CCS V5.3 relating to C5535 (V3 Simulator) - or perhaps the <stdarg.h>

Here is the effect I am seeing - can anyone confirm if they have the same problem? - Or indeed can see what I am doing wrong.

Background:- Porting an audio codec for use on the C5535 DSP. Have already done it for C6000 which had no problems, but now on the C5535 the functions with variable length argument lists are failing depending on data content on the variables.

I have written this test example to demonstrate the problem.

 

void testFunct_a( int testword , int count, ... );

 

int main(void) {

testFunct_a( 1111, 4444, (long)32800L ); // FAILS ( first argument wrong)
testFunct_a( 2222, 8888, (long)32760L ); // PASSES
printf("Hello World!\n");
while(1);
return 0;

}

 

void testFunct_a( int testword , int count, ... )
{

va_list ap;
va_start(ap, count);
printf("count %0d \n",testword);
printf("count %0d \n",count);
long value = va_arg(ap, long);
printf("count %8.8ld \n",(long)value);
va_end(ap);
return;

}

 

The console display output:-

count 0
count 4444
count 00032800
count 2222
count 8888
count 00032760

 

The closest I have got to understanding this is that as the constant value 32800 / 32760 goes over the boundary for a singed int (16bits) then the parameters list in stack changes somehow.

I really need a solution to this - either what I am doing wrong or if this is a compiler bug. The codec being ported uses a lot of variable length argument list functions - if these won't work on the C55 platform I need to start porting all those functions.

Any help much appreciated.

 

Some of things I think might be related..

1)  I read in the C55 datasheet bytes and ints are both 16bit. But more alarmingly doing a sizeof(byte) or a sizeof(int) actually returns 1? (This is detailed in page 84 of SPRU281G TMS320C55x Language manual). Does Stdarg.h use sizeof? etc.

 

 

Rob

 

www.microdex.co.uk

 

 

 

  • I am unable to reproduce your results.  Please show me all the compiler build options and the link command file.  I presume you are using compiler (not CCS) verison 4.4.1.  Is that correct?

    A few other easy things to check on ... Must #include <stdarg.h> and <stdio.h>.  Could you be running out of stack or heap? 

    Thanks and regards,

    -George

  • Hi George,

    Compiler is TI v4.4.1

    stdarg.h & stdio.h are included (sorry didn't show this in the post information)

    Stack and heap were my first considerations, but these are set to huge amounts (heap = 0xf000 ), (stack = 0x8000). The main codec does use a lot of stack and heap, but in the test code I posted here I had removed the main codec from the build.

    Link command file:- (sorry had to rename to .txt as cant upload .cmd here).

    /****************************************************************************/
    /*  C5535.cmd                                                               */
    /*  Copyright (c) 2012  Texas Instruments Incorporated                      */
    /*  Author: Rafael de Souza                                                 */
    /*                                                                          */
    /*    Description: This file is a sample linker command file that can be    */
    /*                 used for linking programs built with the C compiler and  */
    /*                 running the resulting .out file on a C5535.              */
    /*                 Use it as a guideline.  You will want to                 */
    /*                 change the memory layout to match your specific          */
    /*                 target system.  You may want to change the allocation    */
    /*                 scheme according to the size of your program.            */
    /*                                                                          */
    /****************************************************************************/
    
    MEMORY
    {
        MMR:     o = 0x000000  l = 0x0000c0  /* 192B Memory Mapped Registers */
        DARAM0:  o = 0x0000C0  l = 0x00FF40  /* 64KB - MMRS */
    
        SARAM0:   o = 0x010000  l = 0x010000  /* 64KB Single Access RAM 0 */
        SARAM1:   o = 0x020000  l = 0x020000  /* 128kB Single Access RAM 1 */
        SARAM2:   o = 0x040000  l = 0x010000  /* 64kB Single Access RAM 2 */
      
                        
        ROM:     o = 0xFE0000  l = 0x01FF00  /* 128kB ROM (MPNMC=0) or CS5 (MPNMC=1) */
        VECS:    o = 0xFFFF00  l = 0x000100  /* reset vector */
    }                   
                        
    SECTIONS            
    {                   
        vectors (NOLOAD) >  VECS  /* If MPNMC = 1, remove the NOLOAD directive */
        .cinit         >  SARAM2
        .text          >  SARAM1 | SARAM2 | SARAM0
        .stack         >  DARAM0
        .sysstack      >  DARAM0
        .sysmem        >  DARAM0 | SARAM0 | SARAM1
        .data          >  DARAM0 | SARAM0 | SARAM1
        .cio           >  SARAM2
        .bss           >  DARAM0 | SARAM0 | SARAM1
        .const         >  DARAM0 | SARAM0 | SARAM1
        .switch		   >  DARAM0 | SARAM0 | SARAM1
    }
    

    Not sure how to show you give you compiler options? ... (I think this covers it less my file include paths)
    -v5515
    --memory_model=large
    -g
    --ptrdioff_size=16
    --display_error_number
    --diag_warning=225.

    Best Regards

    Rob

     

     

     

     

  • Hi George,

     

    Some more information.

    I have just discovered the simulator was set to C55 cycle accurate Rev 2 - And the error occurs.

    Switching to C55 Cycle accurate Rev 3 - no error.

     

    Any ideas what the difference might be?

     

    Rob

     

  • Well, if it was a compiler problem it would fail with both simulators.  This is likely some problem with the Rev 2 simulator.  I have no expertise in simulators.  Why not just use the Rev 3 simulator?

    Thanks and regards,

    -George

  • You've compiled your program with -v5515, which is a CPU rev 3 device.  When you do this, the compiler can make use of certain addressing constructs that won't always work properly on rev 2, due to the difference in the address generation unit.  It's possible you've stumbled into one of those.  If you use -v5515, you must use the rev 3 simulator.