STM32/STM8技术william hill官网
直播中

casy

12年用户 229经验值
擅长:嵌入式技术
私信 关注
[资料]

【NUCLEO-F412ZG试用体验】5.用sin_cos函数对PFU性能进行残暴测评~

       对于Cortex-M0或者M3处理器类型,由于没有FPU因此无法直接进行浮点运算,
只能将浮点数进行Q规格化 (q7、 q15或Q31)处理,如开平方运算:
M0/M3只能通过迭代法 ( 标准数学函数库 ) 计算,而M4直接调用VSQRT指令完成!
写了一个fpu_test.c

  1. #include "fpu_test.h"

  2. //float32_t arm_sin_f32(float32_t x);
  3. //float32_t arm_cos_f32(float32_t x);
  4. //static __INLINE arm_status  arm_sqrt_f32(float32_t in, float32_t *pOut)

  5. /* ----------------------------------------------------------------------
  6. * Test input data for Floating point sin_cos example for 32-blockSize
  7. * Generated by the matlab randn() function
  8. * ------------------------------------------------------------------- */

  9. const float32_t testInput_f32[MAX_BLOCKSIZE] =
  10. {
  11.   -1.244916875853235400,  -4.793533929171324800,   0.360705030233248850,   0.827929644170887320,  -3.299532218312426900,   3.427441903227623800,   3.422401784294607700,  -0.108308165334010680,
  12.    0.941943896490312180,   0.502609575000365850,  -0.537345278736373500,   2.088817392965764500,  -1.693168684143455700,   6.283185307179590700,  -0.392545884746175080,   0.327893095115825040,
  13.    3.070147440456292300,   0.170611405884662230,  -0.275275082396073010,  -2.395492805446796300,   0.847311163536506600,  -3.845517018083148800,   2.055818378415868300,   4.672594161978930800,
  14.   -1.990923030266425800,   2.469305197656249500,   3.609002606064021000,  -4.586736582331667500,  -4.147080139136136300,   1.643756718868359500,  -1.150866392366494800,   1.985805026477433800

  15. };

  16. const float32_t testRefOutput_f32 = 1.000000000;

  17. /* ----------------------------------------------------------------------
  18. * Declare Global variables
  19. * ------------------------------------------------------------------- */
  20. uint32_t blockSize = 32;
  21. float32_t  testOutput;
  22. float32_t  cosOutput;
  23. float32_t  sinOutput;
  24. float32_t  cosSquareOutput;
  25. float32_t  sinSquareOutput;

  26. /* ----------------------------------------------------------------------
  27. * Max magnitude FFT Bin test
  28. * ------------------------------------------------------------------- */

  29. arm_status status;


  30. int32_t float_test(void)
  31. {
  32.   float32_t diff;
  33.   uint32_t i;

  34.   for(i=0; i< blockSize; i++)
  35.   {
  36.     cosOutput = arm_cos_f32(testInput_f32[i]);
  37.     sinOutput = arm_sin_f32(testInput_f32[i]);

  38.     arm_mult_f32(&cosOutput, &cosOutput, &cosSquareOutput, 1);
  39.     arm_mult_f32(&sinOutput, &sinOutput, &sinSquareOutput, 1);

  40.     arm_add_f32(&cosSquareOutput, &sinSquareOutput, &testOutput, 1);

  41.     /* absolute value of difference between ref and test */
  42.     diff = fabsf(testRefOutput_f32 - testOutput);

  43.     /* Comparison of sin_cos value with reference */
  44.     if(diff > DELTA)
  45.     {
  46.        status = ARM_MATH_TEST_FAILURE;
  47.              printf("arm math test failure!!!!rn");
  48.     }
  49.         else
  50.         {
  51.                     printf("arm math test Success!!!!rn");
  52.         }

  53.   }
  54. }
然后把fpu_test.h中的定义贴出来:
  1. #include "STM32f4xx.h"

  2. #include
  3. #include "arm_math.h"
  4. #include "core_cm4.h"

  5. //ARM_MATH_CM4   //要求使用m4的数学库函数,在工程选项卡中定义
  6. int32_t float_test(void);

  7. /* ----------------------------------------------------------------------
  8. * Defines each of the tests performed
  9. * ------------------------------------------------------------------- */
  10. #define MAX_BLOCKSIZE   32
  11. #define DELTA           (0.0001f)


  12. #define    __FPU_PRESENT 1                // FPU开关


  13. #ifndef   __ARMVFP__                    //要求在生成的代码中使用FPU

  14. #define   __ARMVFP__

  15. #endif

ok了,此时串口就会疯狂打印出来计算的数值。


回帖(1)

casy

2016-11-21 22:45:38
zan~~~没有图~
举报

更多回帖

发帖
×
20
完善资料,
赚取积分