Author Topic: Using arm_math from Arduino IDE  (Read 1748 times)

empireryan

  • RFduino Newbie
  • *
  • Posts: 2
  • Karma: +0/-0
    • View Profile
Using arm_math from Arduino IDE
« on: December 02, 2015, 06:46:38 PM »
Hi All,

I'm trying to run the FFT example given in the ARM source. I'm having trouble compiling beyond this point:

Code: [Select]

#define ARM_MATH_CM0
#include <arm_math.h>

uint16_t fftSize = 1024;
uint8_t ifftFlag = 0;
uint8_t doBitReverse = 1;

uint32_t refIndex = 213;
uint32_t testIndex = 0;

void setup() {
  // put your setup code here, to run once:
  arm_status status;
  arm_cfft_radix4_instance_f32 S;
  float32_t maxValue;
 
  status = ARM_MATH_SUCCESS;
  status = arm_cfft_radix4_init_f32(&S, fftSize, ifftFlag, doBitReverse);

}

void loop() {
  // put your main code here, to run repeatedly:

}


Any help on how to do this would be much appreciated.
« Last Edit: December 12, 2015, 05:30:19 PM by tolson »

tolson

  • Global Moderator
  • *****
  • Posts: 866
  • Karma: +20/-0
    • View Profile
    • Thomas Olson Consulting
Re: Using arm_math from Arduino IDE
« Reply #1 on: December 12, 2015, 08:27:29 PM »

I'm trying to run the FFT example given in the ARM source. I'm having trouble compiling beyond this point:


HINT1: The linker hasn't been told where to find CMSIS LIBs.

Find the platform.txt file in your RFduino directory. It is in the same place as the RFDLoader files...
<PathToRFduinoHome>/platform.txt

 Edit the platform.txt file; add this phrase including the quotes to the end of the line that starts with recipe.c.combine.pattern=

 "{build.system.path}/CMSIS/CMSIS/Lib/GCC/libarm_cortexM0l_math.a"

be sure to put a space first.

HINT2: The GCC CMSIS libraries aren't included. For some reason only the ARM compiler ones are.
 
So you need to download from somewhere the CMSIS 3.01 version of...
libarm_cortexM0l_math.a
 for GCC and put it in the RFduino tree like so...
<PathToRFduinoHome>system/CMSIS/CMSIS/Lib/GCC/libarm_cortexM0l_math.a

Restart Arduino IDE.

voila! your code so far will compile.
Have fun!

kalantor

  • RFduino Newbie
  • *
  • Posts: 1
  • Karma: +0/-0
    • View Profile
Re: Using arm_math from Arduino IDE
« Reply #2 on: October 12, 2017, 01:26:17 PM »
Hi Tolson,

Thank you for the hints above, I am trying to run FFT in RFduino and I got a good start from your hints. Now, I couldn't find the version 3.01 of libarm_cortexM0l_math.a after some searching in google. I used version 5 of CMSIS and the library that comes with it, and I could compile and run a test fft sketch. However, I am not getting right results -- if I run it on a loop for the same data, the output keeps changing its element values and reaches a large number quickly, ultimately overflowing. The program also crashes and restarts for some other settings (when running in a loop).

Here's my code.

Code: [Select]
#define ARM_MATH_CM0
#define TEST_LENGTH_SAMPLES 256

#include <arm_math.h>
//#include <arm_const_structs.h>

float32_t testInput_f32_10khz[] = {10,3,1,3,11,21,31,38,40,37,29,19,9,2,1,4,13,23,33,39,40,36,27,17,7,2,1,6,14,25,34,40,40,35,26,15,6,1,1,7,16,27,35,40,39,34,24,14,5,1,2,8,18,28,37,40,39,32,22,12,4,1,3,10,20,30,38,40,38,31,21,10,3,1,3,11,21,31,38,40,37,29,19,9,2,1,4,13,23,33,39,40,36,27,17,8,2,1,6,14,25,34,40,40,35,26,15,6,1,1,7,16,27,35,40,39,34,24,14,5,1,2,8,18,28,37,40,39,32,22,12,4,1,3,10,20,30,38,40,38,31,21,10,3,1,3,11,21,31,38,40,37,29,19,9,2,1,4,13,23,33,39,40,36,27,17,8,2,1,6,14,25,34,40,40,35,26,15,6,1,1,7,16,27,35,40,39,34,24,14,5,1,2,8,18,28,37,40,39,32,22,12,4,1,3,10,20,30,37,40,38,31,21,10,3,1,3,11,21,31,38,40,37,29,19,9,2,1,4,13,23,33,39,40,36,27,17,8,2,1,6,14,25,34,40,40,35,26,15,6,1,1,7,16,27,35};

float32_t testOutput[TEST_LENGTH_SAMPLES/16]; 

uint16_t fftSize = 16;
uint8_t ifftFlag = 0;
uint8_t doBitReverse = 1;

uint32_t refIndex = 213;
uint32_t testIndex = 0;

arm_status sstatus;
arm_cfft_radix4_instance_f32 S;
float32_t maxValue;

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  Serial.println("test");
  sstatus = ARM_MATH_SUCCESS;
  Serial.println(sstatus);
  sstatus = arm_cfft_radix4_init_f32(&S, fftSize, ifftFlag, doBitReverse);
  Serial.println(sstatus);
}

void loop() {
  // put your main code here, to run repeatedly:
/* Process the data through the CFFT/CIFFT module */
  arm_cfft_radix4_f32(&S, testInput_f32_10khz);

  //arm_cfft_f32(&arm_cfft_sR_f32_len256, testInput_f32_10khz, 0, 1);
   
  /* Process the data through the Complex Magnitude Module for 
  calculating the magnitude at each bin */
  arm_cmplx_mag_f32(testInput_f32_10khz, testOutput, 
            fftSize); 
   
  /* Calculates maxValue and returns corresponding BIN value */
  arm_max_f32(testOutput, fftSize, &maxValue, &testIndex);
   
  if(testIndex !=  refIndex)
  {
    sstatus = ARM_MATH_TEST_FAILURE;
  }

  for(int i = 0; i < TEST_LENGTH_SAMPLES; i++) {
    Serial.print(testOutput[i]); Serial.print(",");
    testOutput[i] = 0;
  }

  for(int i = 0; i < TEST_LENGTH_SAMPLES; i++) {
    testInput_f32_10khz[i] = testInput_f32_10khz[i] *2;
  }
 
  Serial.println();
  Serial.print(maxValue); Serial.print(" "); Serial.println(testIndex);

  //sstatus = arm_cfft_radix4_init_f32(&S, fftSize, ifftFlag, doBitReverse);
  //Serial.println(sstatus);

  //while(1);
}


Any idea what's going wrong? Would you happen to know where I could find v3.01 of the library you mentioned?

Thank you.

 

anything