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.

C6457 Problems with the output, with the operation printf()

Hi,

In my project I use CCSv4 (Version: 4.2.0.), and evaluation module TMDSEVM6457L.

The result of the operation printf() in code:

    int i; float s=0.;
    for(i=0;i<20;i++){
    s+=log(i+1.);
    printf("s=%lf\n",s);
    }

is:

s=
s=0.62
s=1.72
s=
s=
s=6.11
s=
s=1s=)s=1s=1s=19.2
s=62.1
s=8s=;s=>s=3s=Bs=38.2
s=DDDR2

I do not understand why such the out of results to the console.

When I was trying to output results to the file,  the results was not correct.

Code:

  Uint32 *pDdr2Data = (Uint32 *)EMIFB_CE0_BASE_ADDR ;
    ft=fopen("res.dat","w");
    tempData = 0xdeadbeef;
    for (index = 0; index < DATA_CNT; index++) {
        pDdr2Data[index] =  tempData;
        fprintf(ft,"0x%llx\n", pDdr2Data[index]);   }

fclose(ft);

Results:


0x7 b406ddeadbeef
0x 2b406ddeadbeef
0x„b406ddeadbeef
0x72b 40deadbeef
0x7 b406ddeadbeef
0x2b406ddeadbeef
0x„b406ddeadbeef
0x72b406ddeadbeef
0x7 b406ddeadbeef
0x 2b 40deadbeef

Please tell me how to display the results of HEX, float and double formats by the printf() /fprintf() function?

  • Konstantin3 said:
    printf("s=%lf\n",s);

    %f or %lf expect the corresponding argument to be type double.  You are passing a float.

    Konstantin3 said:
    fprintf(ft,"0x%llx\n", pDdr2Data[index]);   }

    %llx expects the corresponding argument to be type long long (64-bits).  You are passing a unsigned long (32-bits).

    Thanks and regards,

    -George

  • George has the right idea here (you need to fix your printf format string), but I need to make a correction:

    Georgem said:
    %f or %lf expect the corresponding argument to be type double.  You are passing a float.

    The standard does not allow the format %lf.  It means nothing.

    You must use %f if the argument is a float or double, and you must use %Lf if the argument is a long double.

    Because printf is a variadic function, float arguments are promoted to double.

  • Hi!

    If %f, the results are:

    s=
    s=
    s=
    s=3.06
    s=
    s=6.10
    s=0.11
    s=10.2                                                                                                                                                                                                                                                                                                                                                                                                  10.22
    s=12.2                                                                                                                                                                                                                                                                                                                                                                                                  12.22
    s=14                                                                                                                                        14.22
    s=17.0
    s=19                                                                                                                                        19.22
    s=22.1
    s=84.2                                                                                                                                                                                                                                                                                                                                                                                                  84.22
    s=;7.2                                                                                                                                                                                                                                                                                                                                                                                                  ;7.22
    s=30.2                                                                                                                                                                                                                                                                                                                                                                                                  30.22
    s=33.1                                                                                                                                                                                                                                                                                                                                                                                                  33.11
    s=36                                                                                                                                        36.06
    s=38.2                                                                                                                                                                                                                                                                                                                                                                                                  38.22
    s=41.2     

    The results is not fully correct.

    Another case: if  "s" is denoted as a "double", the results are:

    s=
    s=0s=1s=
    s=4.00
    s=6.00
    s=
    s=1s=1s=1s=17.0  000
    s=39.0
    s=2s=24./  ///
    s=27./
    s=3s=@s=B6./
    s=38./  ///
    s=4

    Why are these results?

  • What version of the compiler are you using (this is not the same as the CCS version). What command-line options are you using?

    Please post a complete, compilable test case demonstrating the problem.  Here is a test case that works properly with the current version:

    #include <stdio.h>
    #include <math.h>
    
    int main()
    {
        int i; float s=0.;
    
        for(i=0;i<20;i++){
            s+=log(i+1.);
            printf("s=%f\n",s);
        }
    }
    

    Here is the output:

    s=0.000000
    s=0.693147
    s=1.791759
    s=3.178054
    s=4.787492
    s=6.579251
    s=8.525162
    s=10.604603
    s=12.801827
    s=15.104412
    s=17.502308
    s=19.987215
    s=22.552164
    s=25.191221
    s=27.899271
    s=30.671860
    s=33.505074
    s=36.395447
    s=39.339886
    s=42.335617
    
  • Yes, maybe he didn't #include <math.h>, in which case the compiler would treat "log" as a function returning type int, which it is not.

  • Oh! I also want to obtain such results, but I don't know where I can see the version of the compiler. I am a beginner in CCSv4. Help me please.

  • I included the <math.h>, but I do not know how to correctly configure the compiler in CCSv4.

  • The version of  TMS320C6x C/C++ Compiler   is    v7.0.3
    Tools Copyright (c) 1996-2010 Texas Instruments Incorporated.

    in the memory map of this application system can't find cahce. Need to initialize it. How do I do? 

    Konstantin3

  • May be due to this application gives incorrectly results.

  • Please compile the test program I posted and run it.  If it does not give the correct results, please post the executable file here.

  • Is the .out file? (executable)

  • May you a send me all this project, with all configuration files?

  • I have found that simulator gives correct results. But, when I connected TMDSEVM6457L evaluation module, load program to it and start, results was incorrect. Optimization was disabled, but results incorrect. Maybe who knows why?

  • Perhaps your linker command file is not correct.  The memories specified in the linker command file need to reflect the memory the device actually has.

    Since it runs on the simulator, it is almost surely not a compiler or linker problem.

  • Linker command file:

    -c
    -heap  0x10000
    -stack 0x30000


    /* Memory Map 1 - the default */
    MEMORY
    {
            /*L1D:     o = 00f00000h   l = 00008000h */
            /*L1P:     o = 00e00000h   l = 00008000h */
            L2:      o = 00800000h   l = 00200000h
    }

    SECTIONS
    {
        .csl_vect   >       L2
        .text       >       L2
        .stack      >       L2
        .bss        >       L2
        .cinit      >       L2
        .cio        >       L2
        .const      >       L2
        .data       >       L2
        .switch     >       L2
        .sysmem     >       L2
        .far        >       L2
        .testMem    >       L2  
        ISRAM       >       L2
    }

  • We can't really do anything with this.  You need to verify that this description of your memory system is accurate.  The presumption is memory starts at 0x00800000, and goes for 0x00200000 bytes.

    Thanks and regards,

    -George