Settings and main points of FPU performance of STM32F4

In addition to the online tutorials, special attention should be paid to adding an f after the number when there are floating-point numbers in the operation. For example, 4.321 is involved in the operation in the expression. . When you don't add f after 4.321, the stm32F405 film doesn't know that it is used as a single-precision float to operate with the FPU. By default, it may be used as a double (I'm not sure), and the operation speed is still very slow. . Remember to add f,,, after all floating-point numbers, sometimes keil will prompt a warning: #1035-D: single-precision operand implicitly converted to double-precision This sentence means that single-precision operations are implicitly converted to double-precision precision operation. At this time, add an f after the single-precision number


The complete define in the settings of keilmdk is USE_STDPERIPH_DRIVER, STM32F4XX, __FPU_PRESENT=1, __FPU_USED=1, ARM_MATH_CM4, __CC_ARM

To have an option in MDK to set usr FPU

The full play of FPU performance of STM32F4-setting points

Floating-point operations have always been a problem for fixed-point CPUs, such as a simple 1.1+1.1. Fixed-point CPUs must complete operations according to the IEEE-754 standard algorithm, which is a complete nightmare for 8-bit microcontrollers, and for 32-bit microcontrollers. It won't improve much either. Although the Q-processing of floating-point numbers can give full play to the operational performance of 32-bit microcontrollers, the precision is limited and will not be too high. For a microcontroller or CPU with an FPU (floating point unit), floating point addition is just a matter of a few instructions.

Now, FPU or hardware floating-point computing capabilities mainly include high-end DSP (such as TI F28335/C6000/DM6XX/OMAP, etc.), general-purpose CPU (X87 math coprocessor) and advanced ARM+DSP processors.

STM32-F4 belongs to the Cortex-M4F architecture. The biggest difference from M0 and M3 is that there is an additional F-float, that is, it supports the floating-point instruction set, so it can be dozens of times higher than M0/M3 when processing mathematical operations. Hundred times the performance, but to fully utilize the mathematical performance of the FPU, some small settings are required:

1. Compilation control options: Although the corresponding code is added to the system_stm32f4XXX.c file of the routine of the STM32F4XX firmware library, it is not available in the STM32F4-Discovery routine used for user evaluation, so when MDK4.23 writes a floating-point operation program , although the compiler correctly generates the V instruction to perform floating-point operations, but because the system_stm32f4XXX.c file does not enable the FPU, the CPU only thinks that it encounters an illegal instruction and jumps to the HardFault_Handler() interrupt. Therefore, to ensure that this error does not occur, the following code must be added to the system_init() function:

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

SCB->CPACR |= ((3UL<<<10*2)|(3UL<<<11*2));

#endif

Because this option is controlled by conditional compilation, it is necessary to add the following statement to the Define of the C++/C++ tab in the project options (Project->OpTIons for target "XXXX"): __FPU_PRESENT=1, __FPU_USED =1. In this way, the code to start the FPU is added when compiling, and the CPU can use the FPU correctly and efficiently to perform simple addition, subtraction, multiplication and division.

But that's not enough. For complex operations, such as trigonometric functions, square root and other operations, if the math.h header file is still used in programming, it will not improve efficiency: because the math.h header file is for all ARM processors, and its operation functions are all It is based on fixed-point CPU and standard algorithm (IEEE-754), and does not foresee the use of FPU. It requires many instructions and complex processes to complete the operation, which increases the operation time. Therefore, in order to give full play to the floating-point function of M4F, you need to use the arm_math.h that comes with the firmware library. This file decides which function method to use according to the compilation control item (__FPU_USED == 1): if the FPU is not used, then Just call the function defined in keil's standard math.h header file; if the FPU is used, it is to use the optimization function that comes with the firmware library to solve the problem.

At the beginning of arm_math are these compilation control information:

#ifndef _ARM_MATH_H

#define _ARM_MATH_H

#define __CMSIS_GENERIC

#if defined (ARM_MATH_CM4)

#include "core_cm4.h"

#elif defined (ARM_MATH_CM3)

#include "core_cm3.h"

#elif defined (ARM_MATH_CM0)

#include "core_cm0.h"

#else

#include "ARMCM4.h"

#warning "Define either ARM_MATH_CM4 OR ARM_MATH_CM3...By Default building on ARM_MATH_CM4..."

#endif

#undef__CMSIS_GENERIC

#include "string.h"

#include "math.h"

That is to say, if CMSIS is not used, the standard library functions that come with keil will be called. Otherwise, the CMSIS definition is used. Because STM32F4 is used here, it should be controlled by ARM_MATH_CM4, that is, add core_cm4.h, otherwise use ARMCM4.h - but when compiling, keil will prompt that this file cannot be found. Therefore, it is necessary to continue adding the statement ARM_MATH_CM4 in the define of the C/C++ tab of the project option.

After adding the above compilation control items, the use of advanced mathematical functions is basically no problem, such as the calculation of sine and cosine trigonometric functions. But it should be noted that if you use functions such as sin(), cos(), sqrt() directly, the result is to call keil's math.h. You can look at the corresponding code during debugging, and its assembly instruction is BL. W__hardfp_xxx. Therefore, to complete the calculation of trigonometric functions at this time, use arm_sin_f32() or arm_cos_f32(), and the usage remains unchanged. The prototypes of these two functions are in arm_sin_f32.c and arm_cos_f32.c respectively. Through the query and interpolation algorithm of the 256-point trigonometric function table, the exact function value of any angle can be obtained, which is much faster than the "original" sin() and cos().

Of course, some exceptions are the development function sqrt(), which is defined in arm_math.h as follows:

staTIc __INLINE arm_statusarm_sqrt_f32 (float32_t in, float32_t *pOut)

{

if (in > 0)

{

//#if __FPU_USED

#if (__FPU_USED == 1) && defined (__CC_ARM)

*pOut = __sqrtf(in);

#else

*pOut = sqrtf(in);

#endif

return (ARM_MATH_SUCCESS);

}

else

{

*pOut = 0.0f;

return (ARM_MATH_ARGUMENT_ERROR);

}

}

Lan Cable

Lan cable include CAT7 Lan Cable, cat6a cable, cat6 cable, cat5e cable.
The length of the lan cable are 1000ft (305m), the usable part of a box cable is about 300 meters. To press the RJ45 connectors, usually needs to consider the consumption of part of zhuan degree, so one box of lan cable is 305 meters.
Home Network Cable is called "twisted pair". About twisted pair:
Twisted Pair (TP), the most commonly used transmission medium in comprehensive wiring projects, consists of two insulated copper wires. By stranding two insulated copper wires together at a certain density, the radio waves emitted by each wire during transmission are offset by those from the other wire, effectively reducing the degree of signal interference.

Twisted-pair wires are usually made of two 22-26 insulated copper wires wrapped around each other, hence the name "twisted-pair wire".In practice, twisted pair consists of several pairs of twisted pair wrapped together in an insulated cable sleeve.If one or more pairs of twisted-wire is placed in an insulating bushing, it becomes a twisted-wire cable. However, in daily life, "twisted-wire" is generally referred to as "twisted-wire".

Lan cable

Lan Cord,Lan Wire,Lan Cable Connector,Flat Ethernet Cable

Shenzhen Kingwire Electronics Co., Ltd. , https://www.kingwires.com