This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

[FAQ] CC2642R: FFT on CC13x2/CC26x2 devices

Part Number: CC2642R
Other Parts Discussed in Thread: CC1312R, CC2652R7, CC1352R, CC1352P, CC2652P, CC2652R

Hi,

Here is some guidance to leverage the DSP possibilities of the CC2642R in order to run FFT operations.

Note:The same guide is applicable to all the CC13xx and CC26xx devices having a Cortex M4F. These include among others CC1312R, CC1352R, CC1352P, CC1352R7, CC2642R, CC2652R, CC2652P, CC2652R7 etc.

 

  • In your project create a new folder named CMSIS to store the header files for the CMSIS library

  • Copy the files stored in <SDK>\source\third_party\cmsis\include inside this new folder
  • Add this folder to the search path: Project > Properties > Build > Arm Compiler > Include Options

 

I have tested this using the "empty" example available in the SDK (<SDK>\examples\rtos\<DEVICE>\drivers\empty) where I have added the example provided with the library.

Here is the modified content of my empty.c file:

0676.empty.c
/*
 * Copyright (c) 2015-2019, Texas Instruments Incorporated
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 *
 * *  Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 *
 * *  Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * *  Neither the name of Texas Instruments Incorporated nor the names of
 *    its contributors may be used to endorse or promote products derived
 *    from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

/*
 *  ======== empty.c ========
 */

/* For usleep() */
#include <unistd.h>
#include <stdint.h>
#include <stddef.h>

/* Driver Header files */
#include <ti/drivers/GPIO.h>
// #include <ti/drivers/I2C.h>
// #include <ti/drivers/SPI.h>
// #include <ti/drivers/UART.h>
// #include <ti/drivers/Watchdog.h>

/* Driver configuration */
#include "ti_drivers_config.h"

#include "arm_math.h"
#include "arm_const_structs.h"

#define TEST_LENGTH_SAMPLES 4096

/* -------------------------------------------------------------------
* This is a fix for undefined __hardfp_sqrtf and __hardfp_sqrt symbols
* ------------------------------------------------------------------- */
int __hardfp_sqrt(int f){ return sqrt(f); }
float32_t __hardfp_sqrtf(float32_t f){ return sqrt(f); }

/* -------------------------------------------------------------------
* External Input and Output buffer Declarations for FFT Bin Example
* ------------------------------------------------------------------- */
extern float32_t testInput_f32_10khz[TEST_LENGTH_SAMPLES];
static float32_t testOutput[TEST_LENGTH_SAMPLES/2];

/* ------------------------------------------------------------------
* Global variables for FFT Bin Example
* ------------------------------------------------------------------- */
uint32_t fftSize = 2048;
uint32_t ifftFlag = 0;
uint32_t doBitReverse = 1;
arm_cfft_instance_f32 varInstCfftF32;
/* Reference index at which max energy of bin occurs */
uint32_t refIndex = 213, testIndex = 0;

/* ----------------------------------------------------------------------
* Max magnitude FFT Bin test
* ------------------------------------------------------------------- */
void MaxMagnitudeFFTBinTest(void)
{
  arm_status status;
  float32_t maxValue;
  status = ARM_MATH_SUCCESS;

  status=arm_cfft_init_f32(&varInstCfftF32,fftSize);


  /* Process the data through the CFFT/CIFFT module */
  GPIO_write(CONFIG_GPIO_LED_0, CONFIG_GPIO_LED_ON);
  GPIO_write(CONFIG_GPIO_LED_1, CONFIG_GPIO_LED_OFF);
  arm_cfft_f32(&varInstCfftF32, testInput_f32_10khz, ifftFlag, doBitReverse); // 2.587ms for 1024 points | 5.820ms for 2048 (280'411 clock cycles)
  GPIO_write(CONFIG_GPIO_LED_0, CONFIG_GPIO_LED_OFF);
  GPIO_write(CONFIG_GPIO_LED_1, CONFIG_GPIO_LED_ON);

  /* Process the data through the Complex Magnitude Module for
  calculating the magnitude at each bin */
  GPIO_write(CONFIG_GPIO_LED_0, CONFIG_GPIO_LED_ON);
  GPIO_write(CONFIG_GPIO_LED_1, CONFIG_GPIO_LED_OFF);
  arm_cmplx_mag_f32(testInput_f32_10khz, testOutput, fftSize); //22.020ms for 1024 points | 44.01 ms for 2048 points (2'128'459 clock cycles)
  GPIO_write(CONFIG_GPIO_LED_0, CONFIG_GPIO_LED_OFF);
  GPIO_write(CONFIG_GPIO_LED_1, CONFIG_GPIO_LED_ON);

  /* Calculates maxValue and returns corresponding BIN value */
  arm_max_f32(testOutput, fftSize, &maxValue, &testIndex);
  status = (testIndex != refIndex) ? ARM_MATH_TEST_FAILURE : ARM_MATH_SUCCESS;

  if (status != ARM_MATH_SUCCESS)
  {
      while (1); // something went wrong
  }
  else
  {
     // everything is working
  }
}


/*
 *  ======== mainThread ========
 */
void *mainThread(void *arg0)
{
    /* Call driver init functions */
    GPIO_init();
    // I2C_init();
    // SPI_init();
    // UART_init();
    // Watchdog_init();

    /* Configure the LED pin */
    GPIO_setConfig(CONFIG_GPIO_LED_0, GPIO_CFG_OUT_STD | GPIO_CFG_OUT_LOW);
    GPIO_setConfig(CONFIG_GPIO_LED_1, GPIO_CFG_OUT_STD | GPIO_CFG_OUT_LOW);

    /* Turn on user LED */

    MaxMagnitudeFFTBinTest(); // 24.77ms



    while (1) {
    }
}

You may also want to review this post, this thread and this app note for additional details.

Best regards,