Other Parts Discussed in Thread: CC1312R, CC2652R7, CC1352R, CC1352P, CC2652P, CC2652R
下面提供了利用 CC2642R 的 DSP 功能运行 FFT 的指南。
注意:该指南同样适用于所有具有 Cortex M4F 的 CC13xx 和 CC26xx 器件,其中包括 CC1312R、CC1352R、CC1352P、CC1352R7、CC2642R、CC2652R、CC2652P、CC2652R7 等
- 下载 CMSIS-DSP 库文件https://github.com/ARM-software/CMSIS_5/blob/5.7.0/CMSIS/DSP/Lib/ARM/arm_cortexM4lf_math.lib
- 将该文件存储在 <SDK>\source\third_party\cmsis\lib 中
- 重命名文件lib
- 下载 https://github.com/ARM-software/CMSIS_5/tree/5.7.0/CMSIS/DSP/Include 中存储的头文件
a. 如果需要这里是我的 <SDK>\source\third_party\cmsis 文件夹cmsis.zip 的内容
- 将它们存储在 <SDK>\source\third_party\cmsis\include 中
- 打开 CCS,导入空示例
- 添加库:“Project”>“Properties”>“Build”>“Arm Linker”>“File Search Path”。添加 third_party/cmsis/lib/math.lib

- 在工程中新建一个名为 CMSIS 的文件夹,用于存储 CMSIS 库的头文件

- 将 <SDK>\source\third_party\cmsis\include 中存储的文件复制到此新文件夹中
- 将此文件夹添加到搜索路径:“Project”>“Properties”>“Build”>“Arm Compiler”>“Include Options”

我已使用 SDK 中提供的“empty”示例 (<SDK>\examples\rtos\<DEVICE>\drivers\empty) 对此进行了测试,并在其中添加了随库提供的示例。
以下是我的 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) {
}
}