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.

array content changed every time reload OR printf no output

Hi,

I debug a simple filter C/asm mix program. I find that if the filter coefficient is set to short, like:

#define N 33

short h[N]=  

{     

-1,2,8,-1,-19,-7,

28,24,-27,-41,14,47,

4,-34,-12,7,-8,15,

55,-8,-113,-41,146,119,

-129,-186,61,197,17,-134}

The content of 'h' will change every time the program reloaded in software simulator (CCS v5.2.1, Windows 7). This is annoying that I have to exit Debug and re-enter Debug. This costs much more time to exit and load again.

I find the filter coefficient h can set to 'const short h[N]'. This remedies the content changing problem. But a new problem appears for this arrangement. The printf does not print output in the Console. Even the printf does not output a simple array (not related to 'h' at all), This seems that a new memory segment (from const short) inflicts the printf function.

I cannot find a method to solve the two problem at once.

Thanks.

  • To make it clear. The printf only works for the first time. Then, 'Restart' or 'Reload Program' will make printf does not work any more. The only way is to exit Debug and Re-enter software simulator debug mode.

  •  The example is shown below the dot line. h is the filter coefficient array. The commented out printf is desired. The present printf (simplified to show the problem) shows that a simple array 'a' cannot output correctly with 'const short h[N]'.

      

    ..........

    int a[32]={1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32};

    for (i=0; i<30; i++)  {

    temp = sample_data[i];

        y_out[i] = fircircfunc_ext(temp, h, N);

    //    printf("y_out[%d]=%d\n", i, y_out[i]);

       printf("a[%d]=%d\n", i, a[i]);

      }

  • Hi Robert,

    What is your target device?  C6000, C5000 or other?  What simulator are you using (for example, C6678 functional simulator little endian, etc.)?

    Regards,
    Atsushi

  • Target device C6678, cycle accurate simulation. Thanks,

  • Robert W said:
    Target device C6678, cycle accurate simulation. Thanks,

    Thanks Robert. Could you also send me your project + executable?

    ki

  • Hi,

    I find that there is no printf problem for an all C program. The no printf output problem appears when it has an assembly function. I attach the asm header part below the dot line. Is the section or something different with the all C program?

     

    Thanks,

     

     

    .......................

             .def   fircircfunc_ext

        .def   last_addr

             .def   delays

        .def   last_addr0

             .def   delays0

       

    .sect  "circdata"  ;circular data section

             

    .align 256         ;align delay buffer 256-byte boundary

    delays      .space 256*2 

    ;init 256-byte buffer with 0's

    last_addr .int   last_addr-1

    delays0     .space 256*2      

    ;init 256-byte buffer with 0's

    last_addr0 .int   delays0           

    .text    ;code section

    fircircfunc_ext:   ;FIR function using circ addr

  • <link removed by moderator>

    Please remove it after you download. thanks.

  • got it. Thanks!

  • I find the cause of the problem. If

        y_out[i] = fircircfunc_ext(temp, h, N8);

    is replaced by:

        sum0 = fircircfunc_ext(temp, h, N8);

    The printf problem will disappear. Could you explain what error in the y_out[i] line is? Besides using direct variable as the lvalue, could the array be used in addition with some qualifier or so to correct it?

     

    Thanks.

  • Hi,

    I try below lines. The problem appears again. It is obvious that the compiler optimizing out sum0. So, what solution to store the result to an array? Thanks.

     

    ...........

        sum0 = fircircfunc_ext(temp, h, N);

    //    y_out[i] = fircircfunc_ext(temp, h, 128);

        y_out[i]=sum0;

       

    printf("y_out[%d]=%d\n", i, y_out[i]);

  • It's highly unlikely that this segment of code is the root cause.  Most likely, this is just where you notice the difference when the program fails.

    You've mentioned that neither "restart" and "reload" will fix the problem.  What about "reset" ?

    Are you using RAM model (-cr) or ROM model (-c)?

  • Hi,

    This is in software simulator debug mode. Is there a 'Reset' icon (button)? I do not configure RAM or ROM yet.

  • There is a "Reset CPU" button, which looks like a little black chip.

    What are your complete linker options?  This should show up in the build window.

  • I tried Reset button. I do not see changes.

    I change the return variable of asm function to global variable. It works no problem. This seems the printf requirement. Thanks,

  • How is y_out[] declared? Maybe try a static global. Or local on the stack.

  • When I declare it out of main(), there is no printf problem.

    Do you mean that a local variable on the stack? I don't know How to declare it. Thanks.

  • It sounds like you are running out of stack memory. Never used the simulator. I don't know where to adjust the size of the stack. It is likely printf() uses a lot of stack and it probably eat into the heap.


    int heap_y_out[32]; /* Allocated on heap*/

    void main(void)
    {
      int stack_y_out[32]; /* Allocated on stack */
    }

  • Robert W said:
    This seems the printf requirement

    I'm glad you have found a workaround for your problem, but please understand that it is not a requirement of printf that its argument be a global variable.  You have found a way to mask the problem, but it is just as likely that the problem will pop up again when your program grows in other places.  If you want to be sure the problem is fixed, we'll need to pursue the symptoms you have previously described.  If you don't wish do pursue it at this time, that's fine; just be aware it could happen again.