Quality RTOS & Embedded Software

 Real time embedded FreeRTOS RSS feed 
Quick Start Supported MCUs PDF Books Trace Tools Ecosystem


Loading

Problem with FFT Functions in FreeRTOS

Posted by moh-ferdows on November 30, 2017

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 armcfftradix4f3,armrfft_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.


Problem with FFT Functions in FreeRTOS

Posted by kenchang1 on November 30, 2017

Are you using the FPU (floating point calculations)? Try this define #define configUSE_TASK_FPU_SUPPORT 2


Problem with FFT Functions in FreeRTOS

Posted by rtel on December 1, 2017

I don't think configUSETASKFPU_SUPPORT has any effect for the STM32.

Do you have stack overflow checking turned on? https://www.freertos.org/Stacks-and-stack-overflow-checking.html

How are you passing the data via a queue? Do you just queue a pointer to the data? That might not work if the array is on the stack but the tack frame no longer exists. I presume you are talking about the task stack, not the stack of main(), as the main() stack will also no longer exist.


Problem with FFT Functions in FreeRTOS

Posted by moh-ferdows on December 2, 2017

Stack overflow method 1 is turned on. Heap size for my task is sufficeint and no overflow is occurred. I pass data via queue using pointer to an array defined in task stack. Note that I use cmsis-rtos functions so instead of xQueueSend or xQueueReceive I have osMailPut and osMailGet but they are defined based on freeRTOS functions as you know. Here is my code: void waveformFFT(float32t *input,float32t *output,uint16_t fftSize) {

armcfftradix4instancef32 fftStruct; armcfftradix4initf32(&fftStruct,fftSize,0,1); armcfftradix4f32(&fftStruct,input); armcmplxmagf32(input, output, fftSize); } // waveformProcess task void waveformProccess(void const * argument) { /* USER CODE BEGIN waveformProccess / uint16t i,j,k; osEvent tenCycle; uint16t buffAddr,waveSample; uint8t hBuff[4480]; uint8t cylceNum; int32t waveBuff[256]; float32t fftRes[256]; char uartBuff[20]; waveformInfo *waveInfo= (waveformInfo *)osMailAlloc(waveToUarthandle,100); / Infinite loop / for(;;) { tenCycle=osSignalWait(BIT0,200); // waits for recieveing waveform ten cycle samples. if(tenCycle.status == osEventSignal) { for(i=0;i<4480;i++) hBuff[i]=hBufft[i]; for(i=0 ; i <160 ; i++){ waveBuff[160cylceNum+i]=(uint32t)(hBuff[28*i+4] << 24 ) | (uint32t)(hBuff[28i+5] << 16 ) | (uint32_t)(hBuff[28i+6] << 8 ) | (uint32t)(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]; } waveformFFT((float32t )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 */ } I have the same problem if I use cmsis-dsp function directly in the task ( instead of calling a function like waveformProccess in which cmsis-dsp functions are called) Please help me with this problem/ Thanks


Problem with FFT Functions in FreeRTOS

Posted by moh-ferdows on December 2, 2017

Yes,I'm using FPU. configUSETASKFPU_SUPPORT was defined 1. I did so ( defining as 2) but still have the problem.


Problem with FFT Functions in FreeRTOS

Posted by heinbali01 on December 2, 2017

Mahammad, when posting code, please put it between two lines that only contain three tildas ~~~ In that way the text will be show literally:

~~~ ~~~ // waveformProcess task void waveformProccess(void const * argument) { /* USER CODE BEGIN waveformProccess */ uint16t i,j,k; osEvent tenCycle; uint16t buffAddr,waveSample; uint8t hBuff[4480]; uint8t cylceNum; int32t waveBuff[256]; float32t fftRes[256]; char uartBuff[20]; waveformInfo waveInfo= (waveformInfo )osMailAlloc(waveToUarthandle,100);

~~~ ~~~

Could it be that you allocate about 8612 bytes on the stack? Does the task that runs this code have at least 8612 / 4 = 2153 words of stack space?


Problem with FFT Functions in FreeRTOS

Posted by heinbali01 on December 2, 2017

I pressed on Post too early, wanted to ask you more:

Can you make sure that all floating point variables on stack are well-aligned?

but using global variables in freeRTOS tasks can cause some problems as we know

I don't know, why? It is considered as "bad practice" to use global variables, but they don't cause problems as such. You can also make them static within the module, or static within the function. When you do that, the function can run with a normal-size stack.

Don't you check the result of osMailAlloc()? Can it fail?

but send output to another task using queues I receive zero values there!!

How do you send these values? Does each byte go into a FreeRTOS queue? Or do you allocate a new buffer and pass a pointer ( and the ownership ) of the buffer to the queue?


[ Back to the top ]    [ About FreeRTOS ]    [ Privacy ]    [ Sitemap ]    [ ]


Copyright (C) Amazon Web Services, Inc. or its affiliates. All rights reserved.

Latest News

Version 10.1.1 of the FreeRTOS kernel is available for immediate download. MIT licensed.

View a recording of the "OTA Update Security and Reliability" webinar, presented by TI and AWS.


Careers

FreeRTOS and other embedded software careers at AWS.



FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

Espressif ESP32

IAR Partner

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers

Renesas

STMicro RTOS partner supporting ARM7, ARM Cortex-M3, ARM Cortex-M4 and ARM Cortex-M0

Texas Instruments MCU Developer Network RTOS partner for ARM and MSP430 microcontrollers

OpenRTOS and SafeRTOS

Xilinx Microblaze and Zynq partner