Floating Point Unit (FPU) is a unit used to process floating point operations.
In order to use the FPU, in addition to enabling the FPU, you also need to set the compiler to generate special instructions for floating-point operations. Although these two tasks are completed by default in the project template used by the development board in Atmel Studio 6, this time we still introduce the setting method and simply test the efficiency of the FPU.
1. Compiler Settings
In AS6.1 SP2, the compiler used is arm-none-eabi-gcc.exe, version 4.7.3, where "none" means no operating system is specified, and "eabi" means the binary file interface used is eabi.
In ARM GCC, you can set the floating point ABI using the -mfloat-abi option:
The compiler used by AS6.1 uses the soft option by default. To use the FPU, the softfp option will be used here.
soft: Call the soft floating-point library to support floating-point operations. Common instructions are used in GCC to simulate floating-point operations.
softfp: Use FPU for floating point operations. However, when calling functions, general registers are still used to pass floating point parameters. This requires additional type conversion overhead.
hard: Use the FPU for floating-point operations. When calling a function, use the FPU's registers to pass floating-point parameters.
Use the -mfpu option to set the type of FPU hardware.
SAM4E is equipped with the Cortex-M4F FPU, which implements the FPv4-SP version (SP stands for single precision) of the floating point extension. In addition, it also has 32 32-bit single-precision registers, which can also be used as 16 64-bit double-precision registers for load, store and move operations.
So you need to assign -mfpu to fpv4-sp-d16, where d16 means there are 16 64-bit registers.
Settings in AS6.
In the Solution Explorer, right-click the project and go to the Properties page. Then select the Toolchain tab and select ARM/GUN C Compiler.
Note that modifications also need to be made in the Release version configuration.
2. Enable FPU
When the board is reset, the FPU is disabled. However, the startup file used in AS6 will enable the FPU according to the compiler settings.
How to enable FPU
Writing 0b11 to the CP10 and CP11 fields of the FPU's CPACR register will open up full access to the FPU. In addition, this register can only be read and written in privileged mode.
In CMSIS, the address of this register is defined as a reserved address. However, the corresponding API is provided in fpu.h:
12#include// Will conflict with sam.h macro definitions, use board.h fpu_enable();The implementation of fpu_enable() is as follows:
12345678910111213141516/** CPACR register */#define ADDR_CPACR 0xE000ED88#define REG_CPACR (*((volatile uint32_t *)ADDR_CPACR))/** Save the current interrupt status of the CPU and mask it*/irqflags_t flags;flags = cpu_irq_save();/** Modify CPACR register */REG_CPACR |= (0xFu << 20);__DSB(); /** Wait for register modification to complete*/__ISB(); /** Clear the processor pipeline *//** Decide whether to re-enable interrupts based on the settings */cpu_irq_restore(flags);What has been done in AS6
In the AS6 project template used by the development board, the program entry function is Reset_Handler().
Therefore, you only need to set the compiler parameters to automatically enable the FPU.
PS: __GNUC__ is a macro predefined in the GCC compiler, __VFP_FP__ is predefined when GCC enables floating-point operations, and __SOFTFP__ is predefined when soft-emulated floating-point operations are used. GCC can print out predefined macros using the "-dM –E" parameter.
Before calling the main() function, the function executes the following code:
123#if __FPU_USEDfpu_enable();#endif__FPU_USED is defined in the following code:
12345678910//.../* Determine whether the compiler used is GCC */#elif defined ( __GNUC__ )/* Determine whether floating-point operations are enabled and the operations are not implemented by software*/#if defined (__VFP_FP__) && !defined(__SOFTFP__)/* Determine whether the target platform has FPU */#if (__FPU_PRESENT == 1)#define __FPU_USED 1#else//...__FPU_PRESENT is defined in sam4e16e.h:
12/**< SAM4E16E does provide a FPU */#define __FPU_PRESENT 1
3. Testing
In the first example tutorial, we used an empty loop to delay and complete the LED blinking. Here, we modify the loop body of this empty loop to operate on a floating point number. Then observe the difference in the LED blinking frequency when using or not using the hardware FPU.
Modify the delay function as follows:
1 2 3 4 5 6 | void Delay(int num) { volatile float f = 1.0f; for (volatile int i = 0; i < 1024 * 64 * num; ++i ) f*= 1.1f; } |
Then compile and execute the program using the “-mfloat-abi=softfp” and “-mfloat-abi=soft” options respectively, and observe the frequency of the LED flashing.
Previous article:SAM4E MCU Tour - 22. Introduction and initialization of GMAC and PHY
Next article:SAM4E MCU Tour - 24. Using DSP Library to Find Vector Dot Product
- Popular Resources
- Popular amplifiers
- Learn ARM development(16)
- Learn ARM development(17)
- Learn ARM development(18)
- Embedded system debugging simulation tool
- A small question that has been bothering me recently has finally been solved~~
- Learn ARM development (1)
- Learn ARM development (2)
- Learn ARM development (4)
- Learn ARM development (6)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- LED chemical incompatibility test to see which chemicals LEDs can be used with
- Application of ARM9 hardware coprocessor on WinCE embedded motherboard
- What are the key points for selecting rotor flowmeter?
- LM317 high power charger circuit
- A brief analysis of Embest's application and development of embedded medical devices
- Single-phase RC protection circuit
- stm32 PVD programmable voltage monitor
- Introduction and measurement of edge trigger and level trigger of 51 single chip microcomputer
- Improved design of Linux system software shell protection technology
- What to do if the ABB robot protection device stops
- CGD and Qorvo to jointly revolutionize motor control solutions
- CGD and Qorvo to jointly revolutionize motor control solutions
- Keysight Technologies FieldFox handheld analyzer with VDI spread spectrum module to achieve millimeter wave analysis function
- Infineon's PASCO2V15 XENSIV PAS CO2 5V Sensor Now Available at Mouser for Accurate CO2 Level Measurement
- Advanced gameplay, Harting takes your PCB board connection to a new level!
- Advanced gameplay, Harting takes your PCB board connection to a new level!
- A new chapter in Great Wall Motors R&D: solid-state battery technology leads the future
- Naxin Micro provides full-scenario GaN driver IC solutions
- Interpreting Huawei’s new solid-state battery patent, will it challenge CATL in 2030?
- Are pure electric/plug-in hybrid vehicles going crazy? A Chinese company has launched the world's first -40℃ dischargeable hybrid battery that is not afraid of cold
- IL0389 Electronic Paper (Ink Screen) Driver
- Please advise: What is the impact of wireless modules working in a wide voltage range?
- [Perf-V Review] + First Look at Pengfeng Artix 7 FPGA Development Kit
- Can a 0805 SMD LED be lit with a current of 1.25mA?
- EEWORLD University Hall----Live Replay: Microchip Security Series 17 - Pre-configured Wi-Fi? MCUs accelerate time to market and simplify production
- [National Technology N32 MCU Development Package] --N32G030 Series
- Domestic MCU manufacturers are also starting to roll
- The problem of being unable to sample data when using the 28335 ADC module to sample current
- FPGA_100 Days of Journey_Vending Machine
- About Allegro copper plating