...
To enable floating point support, the following kernel config option should be set: CONFIG_VFPM=y
. Without this option, a process using floating point instructions will get a SIGSEGV
.
Floating-point instructions for Cortex-M4 are enabled with the -mfpu=fpv4-sp-d16
compiler option. This option is enabled in the toolchain by default.
...
On the host activate the development environment (refer to Installing and Activating Cross Development Environment ):
Code Block $ . ./ACTIVATE.sh
Create a simple fpu C application on the host:
Code Block $ cd /tmp $ vi check_float.c #include <stdio.h> #include <stdlib.h> #include <sys/time.h> #include <err.h> int main(int argc, char **argv) { register int n; register int i; struct timeval start, end; float x = 0.3f, y = 2.0f, z = 0.0f; n = atoi(argv[1] ? argv[1] : ""); if (n <= 0) n = 50000000; if (gettimeofday(&start, NULL)) err(1, "gettimeofday"); for (i = 0; i < n; i++) { z += x * y; x += 0.00001f; y -= 0.00001f; } if (gettimeofday(&end, NULL)) err(1, "gettimeofday"); long usecs = (end.tv_sec - start.tv_sec) * 1000000 + end.tv_usec - start.tv_usec; printf("%i loops: x=%f, y=%f, z=%f time spent: %ld.%06ld\n", n, x, y, z, usecs / 1000000, usecs % 1000000 ); return 0; }
Build the application for the target with the
-mfloat-abi=soft
GCC flag:Code Block $ ${CROSS_COMPILE_APPS}gcc -o check_float_soft check_float.c -Wall -mfloat-abi=soft -Os
Build the application for the target with the
-mfloat-abi=softfp
GCC flag:Code Block $ ${CROSS_COMPILE_APPS}gcc -o check_float_softfp check_float.c -Wall -mfloat-abi=softfp -Os
Copy the binaries to the directory exported via NFS:
Code Block $ cp check_float_soft check_float_softfp /home/your/nfs/
Run the application binaries on the target. One easy way to do that is to have an NFS share mounted on the target, which immediately provides access to the host development directory:
Code Block / # mount -o nolock 192.168.1.41:/home/yur/nfs /mnt/nfs / # /mnt/nfs/check_float_soft 50000000 loops: x=256.000000, y=-256.000000, z=-1099511627776.000000 time spent: 7.243095 / # /mnt/nfs/check_float_softfp 50000000 loops: x=256.000000, y=-256.000000, z=-1099511627776.000000 time spent: 0.402088 / #
...