cancel
Showing results for 
Search instead for 
Did you mean: 

PROBLEM WITH FFT ON STM32F4

ghfa0098
Associate
Posted on December 11, 2015 at 08:54

I'm going to apply FFT on 512 sized array captured from ADC

BUT as soon as i add libraries like ''arm_math.h''or ''ARMCM4.h'' i get bunch of errors here is my code please someone kindly help me im running out of time I attached files ////////////////////////////////////////////////////////////////////

#include ''stm32f4xx.h''
#include ''system_stm32f4xx.h''
#include ''tm_stm32f4_hd447h''
#include ''stm32f4xx_tim.h''
#include ''stm32f4xx_rcc.h''
#include ''stdlib.h''
#include ''stm32f4xx_gpio.h''
#include ''defines.h''
#include ''arm_math.h''
#include ''arm_const_structs.h''
#include ''math_helper.h''
#include ''system_ARMCM4.h''
#include ''stm32f4xx_adc.h''
#include ''stm32f4xx_dma.h''
#include ''tm_stm32f4_adc.h''
#include ''tm_stm32f4_delay.h''
#include ''tm_stm32f4_gpio.h''
#include ''stdio.h''
#define rezabuffer0 [1024]
uint16_t rezareadadc(ADC_TypeDef* ADCx, uint8_t channel) {
int i1;
ADC_RegularChannelConfig(ADCx, channel, 0, ADC_SampleTime_15Cycles);
ADC_RegularChannelConfig(ADCx, channel, 1, ADC_SampleTime_15Cycles);
ADC_SoftwareStartConv(ADCx);
/* Wait till done */
while (ADC_GetFlagStatus(ADCx, ADC_FLAG_EOC) == RESET);
/* Return result */
return ADC_GetConversionValue(ADCx);
}
int rezafft(){
}
void rezapinsled()
{ 
GPIO_InitTypeDef GPIO_InitStructure;
GPIO_InitTypeDef gpioStructure; 
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD, ENABLE);
gpioStructure.GPIO_Pin = GPIO_Pin_12 | GPIO_Pin_13;
gpioStructure.GPIO_Mode = GPIO_Mode_OUT;
gpioStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOD, &gpioStructure);
// GPIO_WriteBit(GPIOD, GPIO_Pin_12 | GPIO_Pin_13, Bit_RESET);
}
void rezapinsadc(){
GPIO_InitTypeDef GPIO_InitStructure;
GPIO_InitTypeDef gpioStructure; 
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1/* |GPIO_Pin_2 | GPIO_Pin_3
| GPIO_Pin_5 | GPIO_Pin_6*/;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AN;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_Init(GPIOA, &GPIO_InitStructure);
}
void rezatimer()
{
TIM_TimeBaseInitTypeDef timerInitStructure; 
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM7, ENABLE);
timerInitStructure.TIM_Prescaler = 4200;
timerInitStructure.TIM_CounterMode = TIM_CounterMode_Up;
timerInitStructure.TIM_Period = 5;
timerInitStructure.TIM_ClockDivision = TIM_CKD_DIV1;
timerInitStructure.TIM_RepetitionCounter = 0;
TIM_TimeBaseInit(TIM7, &timerInitStructure);
TIM_Cmd(TIM7, ENABLE);
TIM_ITConfig(TIM7, TIM_IT_Update, ENABLE);
}
int rezaintrrupt(){
NVIC_InitTypeDef nvicStructure;
nvicStructure.NVIC_IRQChannel = TIM7_IRQn;
nvicStructure.NVIC_IRQChannelPreemptionPriority = 0;
nvicStructure.NVIC_IRQChannelSubPriority = 0;
nvicStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&nvicStructure);
}
void rezaadcconfg(void)
{
ADC_InitTypeDef ADC_InitStructure;
ADC_CommonInitTypeDef ADC_CommonInitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1, ENABLE);
ADC_CommonInitStructure.ADC_Mode = ADC_Mode_Independent;
ADC_CommonInitStructure.ADC_Prescaler = ADC_Prescaler_Div2;
ADC_CommonInitStructure.ADC_DMAAccessMode = ADC_DMAAccessMode_Disabled;
ADC_CommonInitStructure.ADC_TwoSamplingDelay = ADC_TwoSamplingDelay_5Cycles;
ADC_CommonInit(&ADC_CommonInitStructure);
/* ADC1 Init ****************************************************************/
ADC_InitStructure.ADC_Resolution = ADC_Resolution_6b;
ADC_InitStructure.ADC_ScanConvMode = ENABLE;
ADC_InitStructure.ADC_ContinuousConvMode = ENABLE;
ADC_InitStructure.ADC_ExternalTrigConvEdge = ADC_ExternalTrigConvEdge_None;
ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_T1_CC1;
ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;
ADC_InitStructure.ADC_NbrOfConversion = 1;
}
int main()
{
int j=0,i=0;
int VA[1024];
int IA[1024];
rezapinsled();
rezapinsadc();
rezatimer();
rezaintrrupt();
rezaadcconfg();
while (1){
if (TIM_GetITStatus(TIM2, TIM_IT_Update) != RESET)
{
TIM_ClearITPendingBit(TIM2, TIM_IT_Update);
if (i<1025){
VA[i]=rezareadadc(ADC1,0);
IA[i]=rezareadadc(ADC1,1);
i++;
}
}
}
}

2 REPLIES 2
jbeck17
Associate II
Posted on December 11, 2015 at 14:20

I used FFT on the F0 and only included 

#include ''stm32f0xx_hal.h''

#include ''arm_math.h''

#include ''arm_const_structs.h''

so maybe check the ARM page for how you are performing the entire thing. You need to setup the constant like....

arm_cfft_instance_f32 arm_cfft_sR_f32_len512

and variables  the proper way or you will run into problems. Use the error codes to help you debug. Initially when I made my program I had a lot of errors too and they manifest in one or two simple small errors but after reading the ARM page on FFT it becomes clear very quickly where your errors may be. Don't worry, the code should be very short and simple to add FFT.

Posted on December 12, 2015 at 05:14

If you passed in the right defines on the compiler command line you wouldn't need to have all the individual #includes.

The #include ''stm32f4xx.h'' should pull in the other files via the stm32f4xx_conf.h in your project. You might want to look at the DSP/SPL project templates. Pay special attention to all the settings and configurations deeper within the project options.

When all the errors/warnings come from other files, the value of just supplying main.c is very low, nobody here is going to reconstruct this all from scratch. You need a project and all it's files. I'm not using the TM library, not sure how that mixes things up.

Suggest you start with the first errors/warnings, remedy those, and move forward.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..