cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F4 - FFT : Why global variables

pierre-henri
Associate
Posted on October 16, 2014 at 17:02

Hi,

I'm using CMSIS DSP Libraries with a microcontroller STM32F4 to compute FFT. Here is my function code to compute the FFT:

void fftProcess(float32_t *parSignalInput_f32, float32_t *parfftOutput_f32)

{

    uint16_t i = 0, n = 0;

        

    for (i=0; i<2048; i++)

    {

    hamming_signal_real_img_f32[2*i] =  0;//*(parSignalInput_f32+i);

    hamming_signal_real_img_f32[2*i+1] =  0;

    }

    

    //

    // Calculate RFFT on samples

    //

    arm_cfft_f32(&arm_cfft_sR_f32_len2048, hamming_signal_real_img_f32, INVERT_FFT, BIT_ORDER_FFT);

   

    //

    // Calculate complex power of FFT results

    //

    arm_cmplx_mag_f32(hamming_signal_real_img_f32, g_fFFTResult_f32, NUM_SAMPLES);

    

    

    for(i=0; i< (NUM_SAMPLES/2); i++)

    {

        *(parfftOutput_f32 + i) = g_fFFTResult_f32[i];

    }

    

}

I'm wondering why the next variables: parfftOutput_f32, parSignalInput_f32, g_fFFTResult_f32, hamming_signal_real_img_f32 must be defined as global variables.

If there are not, my program goes in the hardfault handler.

Thanks for your answer,

PH
3 REPLIES 3
Posted on October 16, 2014 at 18:20

Almost certainly doesn't need to be ''global'', but if you use the stack (local/auto), or heap (dynamic), you're going to want to be absolutely sure you're committed enough resources to them.

Things using DMA you might want to be very careful about the memory regions and alignments used, and the temporal nature of the stack with respect to the life of the DMA operation.

http://www.keil.com/forum/58806/

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
pierre-henri
Associate
Posted on October 17, 2014 at 08:41

Thanks Clive1 for this first clue,

I do not use dynamic memory (heap) in my program. 

arm_cfft_f32() and 

arm_cmplx_mag_f32() are two functions from the CMSIS DSP Libraries provided by ARM. So I do not know if DMA is used during their execution. I can understand that the variables which are used in these must be global in this case but I do not understand why the argument of the ''fft_process'' function must be declared in global too. They are not used in DMA process. Moreover, by reading the map file, I see that RAM memory is sufficient (more than 60 ko stays after compilation of my program)

Waiting for your advices,

Thanks,

guoruipang
Associate II
Posted on December 05, 2014 at 09:13

Dear clivel, I use the following procedure to calculate the FFT results of the input data are correct, how to calculate phase?

  /* Process the data through the CFFT/CIFFT module */

  arm_cfft_f32(&arm_cfft_sR_f32_len1024, testInput_f32_10khz, ifftFlag, doBitReverse);

   

  /* Process the data through the Complex Magnitude Module for  

  calculating the magnitude at each bin */

  arm_cmplx_mag_f32(testInput_f32_10khz, testOutput, fftSize);  

   

  /* Calculates maxValue and returns corresponding BIN value */

  arm_max_f32(testOutput, fftSize, &maxValue, &testIndex);