Most ARM-based systems have historically not implemented any form of floating point in hardware. This means that any floating point operations contained in your code will be converted into calls to library functions that then implement the required operations in software.
However many Cortex-M4 based MCUs do incorporate a single precision floating point hardware unit. Note that the optional Cortex-M4 floating point unit implements single precision operations (C/C++ float) only. Thus if your code makes use of double precision floating point (C/C++ double), then any such floating point operations contained in your code will still be converted into calls to library functions that then implement the required operations in software.
Floating Point Variants
When a hardware floating point unit is implemented, ARM define that it may be used in one of two modes.
- Single precision floating point operations are implemented in hardware and hence provide a large performance increase over code that uses traditional floating point library calls, but when calls are made between functions any floating point parameters are passed in ARM (integer) registers or on the stack.
- SoftABI is the 'most compatible' as it allows code that is not built with hardware floating point usage enabled to be linked with code that is built using software floating point library calls.
- Single precision floating point operations are implemented in hardware, and floating point registers are used when passing floating point parameters to functions.
- HardABI will provide the highest absolute floating point performance, but is the 'least compatible' as it means that all of the code base for a project (including all library code) must be built for HardABI.
LPCXpresso IDE generally assumes that when Cortex-M4 hardware floating point is being used, then the SoftABI will be used. Thus generally this is the mode that example code (including for example LPCOpen chip and board libraries) are compiled for. This is done as it ensures that components will tend to work out of the box with each other.
When you use a project wizard for a Cortex-M4 where a hardware floating point unit may be implemented, there will be an option to enable the use of the hardware within the wizard's options. This will default to SoftABI - for compatibility reasons.
Selecting this option will make the appropriate changes to the compiler, assembler and linker settings to cause SoftABI code to be generated. It will also typically enable code within the startup code generated by the wizard that will turn the floating point unit on.
You can also select the use of HardABI in the wizards. Again this will cause appropriate tool settings to be used. But if you use this, you must ensure that any library projects used by your application project are also configured to use HardABI. If such projects already exist, then you can manually modify the compiler/assembler/linker settings in Project Properties to select HardABI.
Warning : Creating a project that uses HardABI when linked library projects have not been configured and built with this option will result in link time errors.
Modifying floating point configuration for an existing project
If you wish to change the floating point ABI for an existing project (for example to change it from using SoftABI to HardABI), then:
In LPCXpresso 7.4.0 and later...
Quickstart -> Quick Settings -> Set Floating Point type
and choose the required option. Or you can make the change manually, as per LPCXpresso 7.3.0 and earlier...
In LPCXpresso 7.3.0 and earlier...
Project -> Properties -> C/C++ Build -> Settings -> Tool Settings
and change the setting in ALL of the following entries:
MCU C Compiler -> Architecture -> Floating point
MCU Assembler -> Architecture & Headers -> Floating point
MCU Linker -> Architecture -> Floating point
Note : For C++ projects, you will also need to modify the setting for the MCU C++ Compiler.
Warning : Remember to change the setting for all associated projects, otherwise linker errors may result.
Do all Cortex-M4 MCUs provide floating point in hardware?
Not all Cortex-M4 based MCUs implement floating point in hardware, so please check the documentation provided for your specific MCU to confirm.
In particular with some MCU families, some specific MCUs may not provide hardware floating point, even though most of the members of the family do (for example the LPC407x_8x). Thus it is a good idea to double check the documentation, even if the project wizard in the LPCXpresso IDE for the family that you are targeting suggests that hardware floating point is available.
Why do I get a hard fault when my code executes a floating point operation?
If you are getting a hard fault when your application tries to execute a floating point operation, then you are almost certainly not enabling the floating point unit. This is normally done in the LPCOpen initialisation code, or if you are not using LPCOpen, then in the startup file that LPCXpresso generates. But if you are not using LPCOpen and you have incorrect compiler/linker options set, then you can run into problems.
For more information, please see the Cortex-M4 Technical Reference Manual, available on the ARM website: