2017-11-30 12:06 AM
Hello,
I'm running freeRTOS on STM32F4. I have no problem with using
cmsis-dsp
functions without freeRTOS.But when I want to call a function (in which cmsis-dsp functions like arm_cfft_radix4_f3,arm_rfft_f32 ,... are called) from a task(thread):
1.If I pass local arrays (defined in that task) as fft input and output ,output becomes zero!!
2.If I pass global arrays, I have non-zero(correct) output, but using global variables in freeRTOS tasks can cause some problems as we know.
3.If I pass global arrays as fft input and output but send output to another task using queues I receive zero values there!!
I don't know if there is problem with freeRTOS variables that is defined in its heap and cmsis-dsp functions defined out of freeRTOS heap.
Here is my code:
// fft function
void waveformFFT(float32_t *input,float32_t *output,uint16_t fftSize)
{ arm_cfft_radix4_instance_f32 fftStruct; arm_cfft_radix4_init_f32(&fftStruct,fftSize,0,1); arm_cfft_radix4_f32(&fftStruct,input); arm_cmplx_mag_f32(input, output, fftSize);}// waveformProcess task
void waveformProccess(void const * argument)
{ /* USER CODE BEGIN waveformProccess */ uint16_t i,j,k; osEvent tenCycle; uint16_t buffAddr,waveSample; uint8_t hBuff[4480]; uint8_t cylceNum;int32_t waveBuff[256]; float32_t fftRes[256];char uartBuff[20]; waveformInfo *waveInfo= (waveformInfo *)osMailAlloc(waveToUarthandle,100); /* Infinite loop */ for(;;) { tenCycle=osSignalWait(BIT_0,200); // waits for recieveing waveform ten cycle samples. if(tenCycle.status == osEventSignal) { for(i=0;i<4480;i++) hBuff[i]=hBuff_t[i]; for(i=0 ; i <160 ; i++){ waveBuff[160*cylceNum+i]=(uint32_t)(hBuff[28*i+4] << 24 ) | (uint32_t)(hBuff[28*i+5] << 16 ) | (uint32_t)(hBuff[28*i+6] << 8 ) | (uint32_t)(hBuff[28*i+7]); // waveInfo->waveform[i]=waveBuff[i]; } cylceNum++;// Take FFT of one cycle of waveform
if(cylceNum==1) { osMailFree(waveToUarthandle,waveInfo); waveformInfo *waveInfo= (waveformInfo *)osMailAlloc(waveToUarthandle,100); for(i=160;i<256;i++) { waveBuff[i]=0; waveInfo->waveform[i]=waveBuff[i]; }waveform
FFT
((float32_t *)waveBuff,fftRes,256); cylceNum = 0; for(i=0;i<256;i++) { waveInfo->waveFFT[i]=fftRes[i]; } osMailPut(waveToUarthandle,waveInfo); // sends fft input and output to uart task using mail. } } } /* USER CODE END waveformProccess */}Thanks.
#cmsis-dsp #fft-stm32f4 #freertos2017-11-30 12:12 AM
uint16_t buffAddr,waveSample;
uint8_t hBuff[4480];
uint8_t cylceNum;
int32_t waveBuff[256];
float32_t fftRes[256];
char uartBuff[20];
Oh boy! You need lots of heap memory for this task!
2017-11-30 02:21 AM
No problem, I have sufficient heap. This task needs less than 2000 words. My total heap is about 25000 words.