STM32 floating point unit (FPU) and DSP library use

====>>> Article summary (with code summary) <<<====

1. Floating point unit (FPU)

Chips targeting M4 and up cores all have FPU floating-point arithmetic units. It can speed up the calculation speed of floating point numbers.

1.1 Hardware used

Hardware: STM32F401CCU6 system board (a system board costs more than ten yuan from Taobao).
Software: CubeMX, Keil (5.38, it is recommended to use the new version, there will be a gray prompt for the part that does not have the macro definition).

1.2 Configuring FPUs

First of all system_stm32f4xx.c, you can see that in the system initialization function, you need to have

  1. __FPU_PRESENT == 1
  2. __FPU_USED ==1

These two definitions are required for configuration.
insert image description here
And the header file is referenced in this file: stm32f4xx.h
insert image description here
referenced stm32f4xx.hin __FPU_PRESENT == 1 has been defined stm32f401xc.h
insert image description here
in .stm32f401xc.h
insert image description here

Then it is short of __FPU_USED ==1 .
Open it core_cm4.h, and you can see that the default __FPU_USED is 0.
Obviously, here is because __TARGET_FPU_VFP is not defined , so the following is not turned on.
insert image description here
So, by definition it's fine. Click the magic wand and add the following definition: ,__TARGET_FPU_VFP. (Note: there is a comma to separate from the front). Then click OK.
If there are some because __CC_ARM is not defined, then just add them.
insert image description here
Then I looked again and found out that __FPU_PRESENT == 1 already exists before, why is it still gray here.
That's because the file that defines __FPU_PRESENT is not included in this file.
insert image description here
Solution 1 (the method of modifying the file is not recommended): reference the file with __FPU_PRESENT defined in this file. As shown below.
insert image description here
Solution 2: __FPU_PRESENT=1UAdd it here again.
Note that 1U is not 1. If it is written as 1, it will stm32f401cx.hbe different from the one defined in , and many redefinition warnings will be reported.
insert image description here

Check it out now. Floating point operations are configured.
insert image description here
Finally, check Use single-precision hardware floating-point operations.
insert image description here

2. CMSIS-DSP

2.1 Add DSP library

Two methods
The first one: directly download the source code, put it in the project folder, and add the header file path.
The second type: add CubeMX.

Use the second one here (how convenient)

Select on the Generate Project page.
insert image description here
Check it and click OK.
insert image description here
After checking, generate the project.
insert image description here
Open the project and you can see that it has been added.
insert image description here
At this time, in the main.c file, add #include "arm_math.h", and then an error will be reported when compiling.
insert image description here
insert image description here

This is because arm_math.hdifferent files are referenced in depending on the kernel type. So the kernel needs to be defined here.

insert image description here
Solution: Just add it according to your own kernel. Here is the M4.
insert image description here
Compile again at this time, and there will be no error.

2.2 Testing

Add code in the main function, you can see .F32 in the debug window.
insert image description here
You can see all the functions and explanations on the official website

====>Official website address<====

Guess you like

Origin blog.csdn.net/weixin_46253745/article/details/129355448