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.

A nasty and undocumented bug in ICFFT_F32 function (DSP lib v1.31)

Other Parts Discussed in Thread: F28M35H52C

Hi all,

I've spent almost a day trying to find a cause of erratic behavior of our F28335 device. We've been using v1.31 FPU library and RFFT and ICFFT routines. Finally I narrow it down to an inverse complex FFT routine. It turned out that, after calling the function, one word in memory was corrupted outside of ICFFT variables (and of course in our case there was some other important variable, that could be responsible for the mess). To be exact, this word is one address above the ebss variables that ICFFT has allocated. It seems that the written value is a pointer to one of the buffers used by ICFFT.

I've checked if there is some newer version of the lib, and there was, 1.40. I look at the revision history: nothing there. But I linked it to my project anyway. And after double checking I'm pretty sure that the bug is gone, no spurious writes to memory (I've checked memory map, because after relinking the write can be somewhere else, maybe even in a hole, so you would not see any problems even when the bug is there).

After that, I compared the source codes of the assembly of the two lib versions. No changes, the codes are the same.

So I've compared the binaries of the ICFFT routines, and they ARE different.

Can someone confirm, that this bug is gone in 1.40? Not only in the case of ICFFT of size 1024 we are using, but in all cases?

Please, TI folks, can you take care of the changelogs of you software, because it could spare a lot of time to us.

Regards, Andy

  • UPDATE:

    This bug occurs as well in ICFFT_F32 routine in the newest DSP library v1.40.

    It occurs when the .ebss section of the ICFFT_F32 aligns to the odd 16-bit address in memory. After calling the ICFFT, the 16-bit word above that address will be corrupted.

    Example of alignment that causes the problem:

    0000ffc0 00000025 FFT.obj (SaramSpecSection)
    0000ffe5 00000014 c28x_fpu_dsp_library.lib : ICFFT_f32.obj (.ebss)

    If you have a variable under the 0000ffe4 address it WILL be corrupted after calling ICFFT_F32().

    Example of alignment when bug does not occur (even address):

    0000ffc0 00000024 FFT.obj (SaramSpecSection)
    0000ffe4 00000014 c28x_fpu_dsp_library.lib : ICFFT_f32.obj (.ebss)

    To pinpoint this I've created a special section (SaramSpecSection) for variables of ICFFT and some dummy buffer, because the linker not always will align it to odd address.

    You can workaround this problem by creating a special ebss section for ICFFT_F32 wit aligning to 32-bit memory address.

    A question to TI folks: How about other FFT routines in the lib? I didn't check them yet.

    Regards, Andy

  • Hi Andy,

    I see the issue. Some of the global variables (32-bit vars) for the FFT routines are placed in the .ebss sector without aligning them on a long word boundary. For example, in the ICFFT routine we have

    _CFFTF32_vars_InPtr         .usect .ebss,2,1,0

    which should have been declared as 

    _CFFTF32_vars_InPtr         .usect .ebss,2,1,1

    That last 1 indicates alignment. if a 32-bit access is taking place it will always read from the even address, so if the variable is a@ 0x25 and you did a 

    MOVL @0x25, ACC, what it actually does is 

    MOVL @0x24, ACC thereby overwriting whatever was at 0x24.

    I will file this as a bug, and yes, its in all the FFT routines in this library. For the time being, your solution of allocating a special .ebss section and aligning it is a good workaround till i release the next revision.

    For example, you use CFFT and ICFFT in your project, in the linker command file add this

    .ebss:fpu_lib      > RAML2, ALIGN=32, PAGE=1
    {
     -l=c28x_fpu_dsp_library.lib<CFFT_f32.obj> (.ebss)
     -l=c28x_fpu_dsp_library.lib<ICFFT_f32.obj> (.ebss)
    }
       
    .ebss            : > RAML2,     PAGE = 1

    In the map file you will see the aligned sections as follows:

    .ebss      1    0000a002    00000019     UNINITIALIZED
                    0000a002    00000010     test_fpu_icfftf32.obj (.ebss)
                    0000a012    00000004     rts2800_fpu32.lib : _lock.obj (.ebss)
                    0000a016    00000004                       : exit.obj (.ebss)
                    0000a01a    00000001                       : errno.obj (.ebss)
    
    .ebss:fpu_lib 
    *          1    0000a020    00000034     UNINITIALIZED
                    0000a020    00000014     c28x_fpu_dsp_library.lib : CFFT_f32.obj (.ebss)
                    0000a034    0000000c     --HOLE--
                    0000a040    00000014                              : ICFFT_f32.obj (.ebss)

    
    

    I apologize for any setbacks this issue may have caused.

     

  • Code doesn't show up

    "

    For example, you use CFFT and ICFFT in your project, in the linker command file add this

    .ebss:fpu_lib > RAML2, ALIGN=32, PAGE=1
    {
    -l=c28x_fpu_dsp_library.lib<CFFT_f32.obj> (.ebss)
    -l=c28x_fpu_dsp_library.lib<ICFFT_f32.obj> (.ebss)
    }

    .ebss : > RAML2, PAGE = 1

    In the map file you will see the aligned sections as follows:


    .ebss 1 0000a002 00000019 UNINITIALIZED
    0000a002 00000010 test_fpu_icfftf32.obj (.ebss)
    0000a012 00000004 rts2800_fpu32.lib : _lock.obj (.ebss)
    0000a016 00000004 : exit.obj (.ebss)
    0000a01a 00000001 : errno.obj (.ebss)

    .ebss:fpu_lib
    * 1 0000a020 00000034 UNINITIALIZED
    0000a020 00000014 c28x_fpu_dsp_library.lib : CFFT_f32.obj (.ebss)
    0000a034 0000000c --HOLE--
    0000a040 00000014 : ICFFT_f32.obj (.ebss)

  • Vishal_Coelho said:
    I will file this as a bug, and yes, its in all the FFT routines in this library.

    Are you sure that the bug occurs in all FFT routines in the library (v1.40)?

    Only the following uses .ebss variables:

    CFFT_F32

    CFFT_F32U

    ICFFT_F32

    It seems that none of the RFFT routines are affected by the bug. Am I right?

    Regards, Andy

  • AndyP said:
    It seems that none of the RFFT routines are affected by the bug. Am I right?

    You are correct, RFFT does not have any .ebss variables. 

    I have filed a bug to check all routines for alignment issues

  • Hi Vishal,

    I'm experiencing bad performance of the cfft_f32 from fpu library.  Very infrequently, the output will be incorrect.  I found this problem because we take the rms value and with a return on a low rms value our software will set a flag.  Going to the root cause, I was able to verify the input buffer to the cfft was correct by performing an fft using excel.  The problem is with the output of the cfft.


    Could this bug be related to my problem? I am using F28M35H52C device.

    Sincerely,

    Suzanne

  • Hi Suzanne,

    I cant say for sure. First, make sure the input buffer to the FFT is aligned to a 4N word boundary in the linker command file. Second, its possible that the odd alignment of the global variables might be causing this issue, in which case i would suggest using the attached source file. You will need to replace the original source file with the attached file and rebuild the library.

    I have corrected the global variable alignment issue in the source code which will be available on the next 1.50.00.00 release (targeted for April).

    If this new version does not fix the issue, please send me the FPU input/output and excel output to check against and ill see if i can find the issue.

    CFFT_f32.asmICFFT_f32.asm