Article Directory
====>>> 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
- __FPU_PRESENT == 1
- __FPU_USED ==1
These two definitions are required for configuration.
And the header file is referenced in this file: stm32f4xx.h
referenced stm32f4xx.h
in __FPU_PRESENT == 1 has been defined stm32f401xc.h
in .stm32f401xc.h
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.
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.
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.
Solution 1 (the method of modifying the file is not recommended): reference the file with __FPU_PRESENT defined in this file. As shown below.
Solution 2: __FPU_PRESENT=1U
Add it here again.
Note that 1U is not 1. If it is written as 1, it will stm32f401cx.h
be different from the one defined in , and many redefinition warnings will be reported.
Check it out now. Floating point operations are configured.
Finally, check Use single-precision hardware floating-point operations.
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.
Check it and click OK.
After checking, generate the project.
Open the project and you can see that it has been added.
At this time, in the main.c file, add #include "arm_math.h", and then an error will be reported when compiling.
This is because arm_math.h
different files are referenced in depending on the kernel type. So the kernel needs to be defined here.
Solution: Just add it according to your own kernel. Here is the M4.
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.
You can see all the functions and explanations on the official website