Hi,
I wanted to build the FFT code for FPB-RA0E1 device, i tried with one but getting error as FLASH OVERFLOW. But the code is just 171 line only. Do you have any example code for the same
Sharing the cod that i have tried
#if BSP_TZ_SECURE_BUILD
FSP_CPP_HEADER
BSP_CMSE_NONSECURE_ENTRY void template_nonsecure_callable ();
/* Trustzone Secure Projects require at least one nonsecure callable function in order to build (Remove this if it is not required to build). */
BSP_CMSE_NONSECURE_ENTRY void template_nonsecure_callable ()
{
}
FSP_CPP_FOOTER
#endif
I wanted to build the FFT code for FPB-RA0E1 device, i tried with one but getting error as FLASH OVERFLOW. But the code is just 171 line only. Do you have any example code for the same
Sharing the cod that i have tried
C-like:
#include "hal_data.h"
#include <../ra/arm/CMSIS-DSP/include/dsp/transform_functions.h>
FSP_CPP_HEADER
void R_BSP_WarmStart(bsp_warm_start_event_t event);
FSP_CPP_FOOTER
/*******************************************************************************************************************//**
* main() is generated by the RA Configuration editor and is used to generate threads if an RTOS is used. This function
* is called by main() when no RTOS is used.
**********************************************************************************************************************/
void hal_entry(void)
{
/* TODO: add your own code here */
/*
* CMSIS FFT
*/
#define SAMPLE_BUFFER_LENGTH 4096
#define SAMPLE_BUFFER_LENGTH_HALF (SAMPLE_BUFFER_LENGTH/2)
#define SAMPLING_RATE 48000
float32_t fft_input[SAMPLE_BUFFER_LENGTH];
float32_t fft_output[SAMPLE_BUFFER_LENGTH];
float32_t fft_power[SAMPLE_BUFFER_LENGTH_HALF];
uint8_t ifftFlag = 0;
float frequency_resolution = (float)SAMPLING_RATE / (float)SAMPLE_BUFFER_LENGTH;
/* write signal to array */
for (int i = 0; i < SAMPLE_BUFFER_LENGTH; i++) {
float32_t r = (float32_t)i/ (float32_t)SAMPLING_RATE;
r *= 3.14159265359 * 2;
r *= 880; // frequency in Hz
float s = sin(r) + sin(r * 4) * 0.5 + sin(r * 3) * 0.25;
fft_input = s;
}
/* analyze signal */
arm_rfft_fast_instance_f32 fft;
arm_rfft_fast_init_f32(&fft, (uint16_t)SAMPLE_BUFFER_LENGTH);
arm_rfft_fast_f32(&fft, fft_input, fft_output, ifftFlag);
arm_cmplx_mag_f32(fft_output, fft_power, (uint32_t)SAMPLE_BUFFER_LENGTH_HALF);
for (int i = 1; i < SAMPLE_BUFFER_LENGTH_HALF; i++) {
//Serial.printf("%i\tfrq: %.1f\tenergy %.6f\r\n", i, i * frequency_resolution, fft_power);
// APP_PRINT("\r\n %i\tfrq: %.1f\tenergy %.6f \r\n", i, i * frequency_resolution, fft_power);
}
/* find dominant frequency */
float32_t maxValue;
uint32_t maxIndex;
arm_max_f32(fft_power, SAMPLE_BUFFER_LENGTH_HALF, &maxValue, &maxIndex);
// Serial.printf("\r\n");
// Serial.printf("max power: %f\r\n", maxValue);
// Serial.printf("max index: %i\r\n", maxIndex);
// Serial.printf("frequency: %f\r\n", (maxIndex * frequency_resolution));
// APP_PRINT("\r\n max power: %f\r\n", maxValue);
// APP_PRINT("\r\n max index: %i\r\n", maxIndex);
// APP_PRINT("\r\n frequency: %f\r\n", (maxIndex * frequency_resolution));
#if BSP_TZ_SECURE_BUILD
/* Enter non-secure code */
R_BSP_NonSecureEnter();
#endif
}
/*******************************************************************************************************************//**
* This function is called at various points during the startup process. This implementation uses the event that is
* called right before main() to set up the pins.
*
* [USER=120004]@Param[/USER][in] event Where at in the start up process the code is currently at
**********************************************************************************************************************/
void R_BSP_WarmStart(bsp_warm_start_event_t event)
{
if (BSP_WARM_START_RESET == event)
{
#if BSP_FEATURE_FLASH_LP_VERSION != 0
/* Enable reading from data flash. */
R_FACI_LP->DFLCTL = 1U;
/* Would normally have to wait tDSTOP(6us) for data flash recovery. Placing the enable here, before clock and
* C runtime initialization, should negate the need for a delay since the initialization will typically take more than 6us. */
#endif
}
if (BSP_WARM_START_POST_C == event)
{
/* C runtime environment and system clocks are setup. */
/* Configure pins. */
R_IOPORT_Open (&IOPORT_CFG_CTRL, &IOPORT_CFG_NAME);
#if BSP_CFG_SDRAM_ENABLED
/* Setup SDRAM and initialize it. Must configure pins first. */
R_BSP_SdramInit(true);
#endif
}
}
#if BSP_TZ_SECURE_BUILD
FSP_CPP_HEADER
BSP_CMSE_NONSECURE_ENTRY void template_nonsecure_callable ();
/* Trustzone Secure Projects require at least one nonsecure callable function in order to build (Remove this if it is not required to build). */
BSP_CMSE_NONSECURE_ENTRY void template_nonsecure_callable ()
{
}
FSP_CPP_FOOTER
#endif