How to use the DSP library of STM32F4

The CPU we usually use is a fixed-point CPU, which means a CPU that performs a whole-point numerical operation. When encountering a floating-point operation of the form 1.1+1.1, the fixed-point CPU encounters a big problem. For 32-bit microcontrollers, Q-processing can be used to perform its own performance, but accuracy and speed still do not improve much.

Now I have designed a new CPU called FPU. This chip specializes in floating point arithmetic, so the processor separates the whole point and the floating point number. The whole point is processed by the fixed point CPU and the floating point number is processed by the FPU. We have seen TI's DSPs, as well as DSP-enabled microcontrollers in the STM32F4 family. The former has not been used by the author, and no comment is made. However, if the latter needs to use the floating-point arithmetic function of the FPU, it must perform some necessary settings.

First, since floating point operations are performed in the FPU, the FPU should be enabled first. In system_init(), define __FPU_PRESENT and __FPU_USED

/* FPU setTIngs---------------------------------------------- --------------*/

#if (__FPU_PRESENT == 1)&& (__FPU_USED == 1)

SCB-"CPACR |= ((3UL "10*2)|(3UL "11*2)); /*set CP10 and CP11 Full Access */

#endif

This enables the FPU.

For the above changes, this simple addition, subtraction, multiplication and division operation FPU occurs in the program. But for complex operations such as trigonometry, square root, etc., we need to add the math.h header file. But if you simply add him, then Keil will automatically call the internal math.h, the header file is for the ARM processor, specifically for fixed-point CPU and standard algorithm (IEEE-754). It does not have any effect on the STM32F4 using the FPU. Therefore, you need to replace math.h with the ST library, arm_math.h. In the header file, another file core_cmx.h (x=0, 3, 4) is involved. Of course, as in the STM32F1 series, core_cm4.h can be added to the project.

Here, it is all set up, the last step of the difference, call! But don't underestimate this step, because if the call is not correct, the previous settings will be wasted. Do not write the above form directly when using trigonometric functions such as sin() or cos(), because their function name comes from math.h, so you are still calling the standard math.h in the Keil library. To use the arm_sin_f32() function in arm_math.h (see Line.5780, see DSP_Lib\Source\FastMathFuncTIons for the original function), you can see that it uses the cubic spline interpolation method for fast evaluation (see Line.263 /* Cubic). interpolaTIon process */).

Note the exception function, sqrt(), which is arm_sqrt_f32() in arm_math.h. When using him, you need to enable #if(__FPU_USED == 1) && defined ( __CC_ARM ) at the same time, remember! You can also find that the square function has q15 and q31 points. I think the difference between them is the accuracy problem, but they don't use the FPU to calculate. To put it bluntly, use the number 0x5f3759df to make a quick square. If you have this number, Unfamiliar, check out http://en.wikipedia.org/wiki/Fast_inverse_square_root. However, his handling may be different.

There are also a lot of DSP functions in DSP_Lib\Source, interested in researching yourself.

Directional Antenna

Directional Antenna WiFi,Directional Antenna TV,Directional Antenna LTE,Directional Antenna Indoor,Directional Antenna Outerdoor

Yetnorson Antenna Co., Ltd. , https://www.xhlantenna.com