summaryrefslogtreecommitdiff
path: root/nuttx
diff options
context:
space:
mode:
authorpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2012-02-23 21:29:42 +0000
committerpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2012-02-23 21:29:42 +0000
commit6537ccc38c1dbb7261b037bf3919bbe6e6c89bf7 (patch)
treefeeb06bdb58e93a0722363f90b2b7dda8f86be4e /nuttx
parentea61dba2159dde7b53fda2bcabdd172a081687ef (diff)
downloadpx4-nuttx-6537ccc38c1dbb7261b037bf3919bbe6e6c89bf7.tar.gz
px4-nuttx-6537ccc38c1dbb7261b037bf3919bbe6e6c89bf7.tar.bz2
px4-nuttx-6537ccc38c1dbb7261b037bf3919bbe6e6c89bf7.zip
Enable STM32 F4 hardware floating point with the Atollic toolchain
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@4418 42af7a65-404d-4744-a932-0658087f49c3
Diffstat (limited to 'nuttx')
-rw-r--r--nuttx/arch/arm/src/armv7-m/up_exception.S1
-rw-r--r--nuttx/arch/arm/src/armv7-m/up_fpu.S24
-rwxr-xr-xnuttx/configs/stm3240g-eval/README.txt75
-rw-r--r--nuttx/configs/stm3240g-eval/dhcpd/Make.defs4
-rw-r--r--nuttx/configs/stm3240g-eval/nettest/Make.defs4
-rw-r--r--nuttx/configs/stm3240g-eval/nsh/Make.defs4
-rw-r--r--nuttx/configs/stm3240g-eval/nsh2/Make.defs4
-rw-r--r--nuttx/configs/stm3240g-eval/ostest/Make.defs4
-rw-r--r--nuttx/configs/stm3240g-eval/telnetd/Make.defs4
-rwxr-xr-xnuttx/configs/stm32f4discovery/README.txt75
-rw-r--r--nuttx/configs/stm32f4discovery/nsh/Make.defs4
-rw-r--r--nuttx/configs/stm32f4discovery/ostest/Make.defs4
12 files changed, 188 insertions, 19 deletions
diff --git a/nuttx/arch/arm/src/armv7-m/up_exception.S b/nuttx/arch/arm/src/armv7-m/up_exception.S
index 091542ea3..31d8dbb0c 100644
--- a/nuttx/arch/arm/src/armv7-m/up_exception.S
+++ b/nuttx/arch/arm/src/armv7-m/up_exception.S
@@ -164,6 +164,7 @@ exception_common:
* context switch time would be improved if we could work out when the stack
* is dirty and avoid the work...
*/
+
add r1, r0, #SW_XCPT_SIZE /* R1=Address of HW save area in reg array */
ldmia r1!, {r4-r11} /* Fetch eight registers in HW save area */
#ifdef CONFIG_ARCH_FPU
diff --git a/nuttx/arch/arm/src/armv7-m/up_fpu.S b/nuttx/arch/arm/src/armv7-m/up_fpu.S
index c301f793e..2983e1e06 100644
--- a/nuttx/arch/arm/src/armv7-m/up_fpu.S
+++ b/nuttx/arch/arm/src/armv7-m/up_fpu.S
@@ -1,7 +1,7 @@
/************************************************************************************
* arch/arm/src/armv7-m/stm32_fpu.S
*
- * Copyright (C) 2011 Gregory Nutt. All rights reserved.
+ * Copyright (C) 2011-2012 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
@@ -91,6 +91,12 @@
up_savefpu:
add r1, r0, #(4*REG_S0) /* R1=Address of FP register storage */
+#if 1
+ vstmdb r1!, {s0-s31} /* Save the full FP context */
+ vmrs r2, fpscr /* Fetch the FPCSR */
+ str r2, [r1], #4 /* Save the floating point control and status register */
+#else
+ add r1, r0, #(4*REG_S0) /* R1=Address of FP register storage */
vmov r2, r3, d0 /* r2, r3 = d0 */
str r2, [r1], #4 /* Save S0 and S1 values */
str r3, [r1], #4
@@ -140,12 +146,13 @@ up_savefpu:
str r2, [r1], #4 /* Save S30 and S31 values */
str r3, [r1], #4
- /* The gnu assembler doesn't support all the new UAL mnemonics.
- * Use the old FMRX and FMXR names instead of 'vmrx r2, fpscr'
+ /* Older GNU assemblers don't support all the new UAL mnemonics.
+ * Use the old FMRX and FMXR names instead of 'vmsx r2, fpscr'
*/
- fmrx r2, fpscr, /* Fetch the FPCSR */
+ fmrx r2, fpscr /* Fetch the FPCSR */
str r2, [r1], #4 /* Save the floating point control and status register */
+#endif
bx lr
.size up_savefpu, .-up_savefpu
@@ -174,6 +181,11 @@ up_savefpu:
up_restorefpu:
add r1, r0, #(4*REG_S0) /* R1=Address of FP register storage */
+#if 1
+ vldmia r1!, {s0-s31} /* Restore the full FP context */
+ ldr r2, [r1], #4 /* Fetch the floating point control and status register */
+ vmsr fpscr, r2 /* Restore the FPCSR */
+#else
ldr r2, [r1], #4 /* Fetch S0 and S1 values */
ldr r3, [r1], #4
vmov d0, r2, r3 /* Save as d0 */
@@ -223,14 +235,16 @@ up_restorefpu:
ldr r3, [r1], #4
vmov d15, r2, r3 /* Save as d15 */
- /* The gnu assembler doesn't support all the new UAL mnemonics.
+ /* Older GNU assemblers don't support all the new UAL mnemonics.
* Use the old FMRX and FMXR names instead of 'vmsr fpscr, r2'
*/
ldr r2, [r1], #4 /* Fetch the floating point control and status register */
fmxr fpscr, r2 /* Restore the FPCSR */
+#endif
bx lr
.size up_restorefpu, .-up_restorefpu
+#endif /* CONFIG_ARCH_FPU */
.end
diff --git a/nuttx/configs/stm3240g-eval/README.txt b/nuttx/configs/stm3240g-eval/README.txt
index 3e47d9db8..2c7c09bdf 100755
--- a/nuttx/configs/stm3240g-eval/README.txt
+++ b/nuttx/configs/stm3240g-eval/README.txt
@@ -115,6 +115,28 @@ GNU Toolchain Options
CONFIG_MOTOROLA_SREC=n
CONFIG_RAW_BINARY=n
+ Another problem that I had with the Atollic toolchain is that the provide a gcc.exe
+ and g++.exe in the same bin/ file as their ARM binaries. If the Atollic bin/ path
+ appears in your PATH variable before /usr/bin, then you will get the wrong gcc
+ when you try to build host executables. This will cause to strange, uninterpretable
+ errors build some host binaries in tools/ when you first make. Here is my
+ workaround kludge.
+
+ 1. Edit the setenv.sh to put the Atollic toolchain at the beginning of the PATH
+ 2. Source the setenv.sh file: . ./setenv.sh. A side effect of this is that it
+ will set an environment variable called PATH_ORIG.
+ 3. Then go back to the original patch: export PATH=$PATH_ORIG
+ 4. Then make. The make will build all of the host executable but will fail
+ when it gets to the first ARM binary.
+ 5. Then source setenv.sh again: . ./setenv.sh. That will correct the PATH
+ again. When you do make again, the host executables are already made and
+ now the correct PATH is in place for the ARM build.
+
+ Also, the Atollic toolchain is the only toolchain that has built-in support for
+ the FPU in these configurations. If you plan to use the Cortex-M4 FPU, you will
+ need to use the Atollic toolchain for now. See the FPU section below for more
+ information.
+
NOTE 3: The devkitARM toolchain includes a version of MSYS make. Make sure that
the paths to Cygwin's /bin and /usr/bin directories appear BEFORE the devkitARM
path or will get the wrong version of make.
@@ -354,15 +376,54 @@ There are two version of the FPU support built into the STM32 port.
CFLAGS
------
-To used the FPU, you will also have to modify the CFLAGS to enable compiler
-support for the ARMv7-M FPU. As of this writing, there are not many GCC
-toolchains that will support the ARMv7-M FPU.
+Only the Atollic toolchain has built-in support for the Cortex-M4 FPU. You will see
+the following lines in each Make.defs file:
+
+ ifeq ($(CONFIG_STM32_ATOLLIC),y)
+ # Atollic toolchain under Windows
+ ...
+ ifeq ($(CONFIG_ARCH_FPU),y)
+ ARCHCPUFLAGS = -mcpu=cortex-m4 -mthumb -march=armv7e-m -mfpu=fpv4-sp-d16 -mfloat-abi=hard
+ else
+ ARCHCPUFLAGS = -mcpu=cortex-m3 -mthumb -mfloat-abi=soft
+ endif
+ endif
+
+If you are using a toolchain other than the Atollic toolchain, then to use the FPU
+you will also have to modify the CFLAGS to enable compiler support for the ARMv7-M
+FPU. As of this writing, there are not many GCC toolchains that will support the
+ARMv7-M FPU.
+
+As a minimum you will need to add CFLAG options to (1) enable hardware floating point
+code generation, and to (2) select the FPU implementation. You might try the same
+options as used with the Atollic toolchain in the Make.defs file:
+
+ ARCHCPUFLAGS = -mcpu=cortex-m4 -mthumb -march=armv7e-m -mfpu=fpv4-sp-d16 -mfloat-abi=hard
+
+Configuration Changes
+---------------------
+
+Below are all of the configuration changes that I had to make to configs/stm3240g-eval/nsh2
+in order to successfully build NuttX using the Atollic toolchain WITH FPU support:
+
+ -CONFIG_ARCH_FPU=y : Enable FPU support
+ +CONFIG_ARCH_FPU=n
+
+ -CONFIG_STM32_CODESOURCERYW=n : Disable the CodeSourcery toolchain
+ +CONFIG_STM32_CODESOURCERYW=y
+
+ -CONFIG_STM32_ATOLLIC=y : Enable the Atollic toolchain
+ +CONFIG_STM32_ATOLLIC=n
+
+ -CONFIG_INTELHEX_BINARY=n : Suppress generation FLASH download formats
+ +CONFIG_INTELHEX_BINARY=y
-As a minimum, you will need to CFLAG options to (1) enable hardware floating
-point code generation, and to (2) select the FPU implementation. You might
-try something like the following in the Make.defs file:
+ -CONFIG_HAVE_CXX=n : Suppress generation of C++ code
+ +CONFIG_HAVE_CXX=y
-ARCHCPUFLAGS = -mcpu=cortex-m4 -mthumb -march=armv7e-m -mfpu=fpv4-sp-d16 -mfloat-abi=hard
+See the section above on Toolchains, NOTE 2, for explanations for some of
+the configuration settings. Some of the usual settings are just not supported
+by the "Lite" version of the Atollic toolchain.
STM3240G-EVAL-specific Configuration Options
============================================
diff --git a/nuttx/configs/stm3240g-eval/dhcpd/Make.defs b/nuttx/configs/stm3240g-eval/dhcpd/Make.defs
index c78a5a047..5de6dec90 100644
--- a/nuttx/configs/stm3240g-eval/dhcpd/Make.defs
+++ b/nuttx/configs/stm3240g-eval/dhcpd/Make.defs
@@ -56,8 +56,12 @@ ifeq ($(CONFIG_STM32_ATOLLIC),y)
CROSSDEV = arm-atollic-eabi-
ARCROSSDEV =
WINTOOL = y
+ifeq ($(CONFIG_ARCH_FPU),y)
+ ARCHCPUFLAGS = -mcpu=cortex-m4 -mthumb -march=armv7e-m -mfpu=fpv4-sp-d16 -mfloat-abi=hard
+else
ARCHCPUFLAGS = -mcpu=cortex-m3 -mthumb -mfloat-abi=soft
endif
+endif
ifeq ($(CONFIG_STM32_DEVKITARM),y)
# devkitARM under Windows
CROSSDEV = arm-eabi-
diff --git a/nuttx/configs/stm3240g-eval/nettest/Make.defs b/nuttx/configs/stm3240g-eval/nettest/Make.defs
index 42cb36f64..50cb6b296 100644
--- a/nuttx/configs/stm3240g-eval/nettest/Make.defs
+++ b/nuttx/configs/stm3240g-eval/nettest/Make.defs
@@ -56,8 +56,12 @@ ifeq ($(CONFIG_STM32_ATOLLIC),y)
CROSSDEV = arm-atollic-eabi-
ARCROSSDEV =
WINTOOL = y
+ifeq ($(CONFIG_ARCH_FPU),y)
+ ARCHCPUFLAGS = -mcpu=cortex-m4 -mthumb -march=armv7e-m -mfpu=fpv4-sp-d16 -mfloat-abi=hard
+else
ARCHCPUFLAGS = -mcpu=cortex-m3 -mthumb -mfloat-abi=soft
endif
+endif
ifeq ($(CONFIG_STM32_DEVKITARM),y)
# devkitARM under Windows
CROSSDEV = arm-eabi-
diff --git a/nuttx/configs/stm3240g-eval/nsh/Make.defs b/nuttx/configs/stm3240g-eval/nsh/Make.defs
index ad84f4038..5904c18c3 100644
--- a/nuttx/configs/stm3240g-eval/nsh/Make.defs
+++ b/nuttx/configs/stm3240g-eval/nsh/Make.defs
@@ -56,8 +56,12 @@ ifeq ($(CONFIG_STM32_ATOLLIC),y)
CROSSDEV = arm-atollic-eabi-
ARCROSSDEV =
WINTOOL = y
+ifeq ($(CONFIG_ARCH_FPU),y)
+ ARCHCPUFLAGS = -mcpu=cortex-m4 -mthumb -march=armv7e-m -mfpu=fpv4-sp-d16 -mfloat-abi=hard
+else
ARCHCPUFLAGS = -mcpu=cortex-m3 -mthumb -mfloat-abi=soft
endif
+endif
ifeq ($(CONFIG_STM32_DEVKITARM),y)
# devkitARM under Windows
CROSSDEV = arm-eabi-
diff --git a/nuttx/configs/stm3240g-eval/nsh2/Make.defs b/nuttx/configs/stm3240g-eval/nsh2/Make.defs
index 10a4346e1..c7fc580d7 100644
--- a/nuttx/configs/stm3240g-eval/nsh2/Make.defs
+++ b/nuttx/configs/stm3240g-eval/nsh2/Make.defs
@@ -56,8 +56,12 @@ ifeq ($(CONFIG_STM32_ATOLLIC),y)
CROSSDEV = arm-atollic-eabi-
ARCROSSDEV =
WINTOOL = y
+ifeq ($(CONFIG_ARCH_FPU),y)
+ ARCHCPUFLAGS = -mcpu=cortex-m4 -mthumb -march=armv7e-m -mfpu=fpv4-sp-d16 -mfloat-abi=hard
+else
ARCHCPUFLAGS = -mcpu=cortex-m3 -mthumb -mfloat-abi=soft
endif
+endif
ifeq ($(CONFIG_STM32_DEVKITARM),y)
# devkitARM under Windows
CROSSDEV = arm-eabi-
diff --git a/nuttx/configs/stm3240g-eval/ostest/Make.defs b/nuttx/configs/stm3240g-eval/ostest/Make.defs
index f49a8c9aa..dc7d728eb 100644
--- a/nuttx/configs/stm3240g-eval/ostest/Make.defs
+++ b/nuttx/configs/stm3240g-eval/ostest/Make.defs
@@ -56,8 +56,12 @@ ifeq ($(CONFIG_STM32_ATOLLIC),y)
CROSSDEV = arm-atollic-eabi-
ARCROSSDEV =
WINTOOL = y
+ifeq ($(CONFIG_ARCH_FPU),y)
+ ARCHCPUFLAGS = -mcpu=cortex-m4 -mthumb -march=armv7e-m -mfpu=fpv4-sp-d16 -mfloat-abi=hard
+else
ARCHCPUFLAGS = -mcpu=cortex-m3 -mthumb -mfloat-abi=soft
endif
+endif
ifeq ($(CONFIG_STM32_DEVKITARM),y)
# devkitARM under Windows
CROSSDEV = arm-eabi-
diff --git a/nuttx/configs/stm3240g-eval/telnetd/Make.defs b/nuttx/configs/stm3240g-eval/telnetd/Make.defs
index fb4c2cc66..0fede585e 100644
--- a/nuttx/configs/stm3240g-eval/telnetd/Make.defs
+++ b/nuttx/configs/stm3240g-eval/telnetd/Make.defs
@@ -56,8 +56,12 @@ ifeq ($(CONFIG_STM32_ATOLLIC),y)
CROSSDEV = arm-atollic-eabi-
ARCROSSDEV =
WINTOOL = y
+ifeq ($(CONFIG_ARCH_FPU),y)
+ ARCHCPUFLAGS = -mcpu=cortex-m4 -mthumb -march=armv7e-m -mfpu=fpv4-sp-d16 -mfloat-abi=hard
+else
ARCHCPUFLAGS = -mcpu=cortex-m3 -mthumb -mfloat-abi=soft
endif
+endif
ifeq ($(CONFIG_STM32_DEVKITARM),y)
# devkitARM under Windows
CROSSDEV = arm-eabi-
diff --git a/nuttx/configs/stm32f4discovery/README.txt b/nuttx/configs/stm32f4discovery/README.txt
index f6aeb3b89..23e45c742 100755
--- a/nuttx/configs/stm32f4discovery/README.txt
+++ b/nuttx/configs/stm32f4discovery/README.txt
@@ -114,6 +114,28 @@ GNU Toolchain Options
CONFIG_MOTOROLA_SREC=n
CONFIG_RAW_BINARY=n
+ Another problem that I had with the Atollic toolchain is that the provide a gcc.exe
+ and g++.exe in the same bin/ file as their ARM binaries. If the Atollic bin/ path
+ appears in your PATH variable before /usr/bin, then you will get the wrong gcc
+ when you try to build host executables. This will cause to strange, uninterpretable
+ errors build some host binaries in tools/ when you first make. Here is my
+ workaround kludge.
+
+ 1. Edit the setenv.sh to put the Atollic toolchain at the beginning of the PATH
+ 2. Source the setenv.sh file: . ./setenv.sh. A side effect of this is that it
+ will set an environment variable called PATH_ORIG.
+ 3. Then go back to the original patch: export PATH=$PATH_ORIG
+ 4. Then make. The make will build all of the host executable but will fail
+ when it gets to the first ARM binary.
+ 5. Then source setenv.sh again: . ./setenv.sh. That will correct the PATH
+ again. When you do make again, the host executables are already made and
+ now the correct PATH is in place for the ARM build.
+
+ Also, the Atollic toolchain is the only toolchain that has built-in support for
+ the FPU in these configurations. If you plan to use the Cortex-M4 FPU, you will
+ need to use the Atollic toolchain for now. See the FPU section below for more
+ information.
+
NOTE 3: The devkitARM toolchain includes a version of MSYS make. Make sure that
the paths to Cygwin's /bin and /usr/bin directories appear BEFORE the devkitARM
path or will get the wrong version of make.
@@ -372,15 +394,54 @@ There are two version of the FPU support built into the STM32 port.
CFLAGS
------
-To used the FPU, you will also have to modify the CFLAGS to enable compiler
-support for the ARMv7-M FPU. As of this writing, there are not many GCC
-toolchains that will support the ARMv7-M FPU.
+Only the Atollic toolchain has built-in support for the Cortex-M4 FPU. You will see
+the following lines in each Make.defs file:
+
+ ifeq ($(CONFIG_STM32_ATOLLIC),y)
+ # Atollic toolchain under Windows
+ ...
+ ifeq ($(CONFIG_ARCH_FPU),y)
+ ARCHCPUFLAGS = -mcpu=cortex-m4 -mthumb -march=armv7e-m -mfpu=fpv4-sp-d16 -mfloat-abi=hard
+ else
+ ARCHCPUFLAGS = -mcpu=cortex-m3 -mthumb -mfloat-abi=soft
+ endif
+ endif
+
+If you are using a toolchain other than the Atollic toolchain, then to use the FPU
+you will also have to modify the CFLAGS to enable compiler support for the ARMv7-M
+FPU. As of this writing, there are not many GCC toolchains that will support the
+ARMv7-M FPU.
+
+As a minimum you will need to add CFLAG options to (1) enable hardware floating point
+code generation, and to (2) select the FPU implementation. You might try the same
+options as used with the Atollic toolchain in the Make.defs file:
+
+ ARCHCPUFLAGS = -mcpu=cortex-m4 -mthumb -march=armv7e-m -mfpu=fpv4-sp-d16 -mfloat-abi=hard
+
+Configuration Changes
+---------------------
+
+Below are all of the configuration changes that I had to make to configs/stm3240g-eval/nsh2
+in order to successfully build NuttX using the Atollic toolchain WITH FPU support:
+
+ -CONFIG_ARCH_FPU=y : Enable FPU support
+ +CONFIG_ARCH_FPU=n
+
+ -CONFIG_STM32_CODESOURCERYW=n : Disable the CodeSourcery toolchain
+ +CONFIG_STM32_CODESOURCERYW=y
+
+ -CONFIG_STM32_ATOLLIC=y : Enable the Atollic toolchain
+ +CONFIG_STM32_ATOLLIC=n
+
+ -CONFIG_INTELHEX_BINARY=n : Suppress generation FLASH download formats
+ +CONFIG_INTELHEX_BINARY=y
-As a minimum, you will need to CFLAG options to (1) enable hardware floating
-point code generation, and to (2) select the FPU implementation. You might
-try something like the following in the Make.defs file:
+ -CONFIG_HAVE_CXX=n : Suppress generation of C++ code
+ +CONFIG_HAVE_CXX=y
-ARCHCPUFLAGS = -mcpu=cortex-m4 -mthumb -march=armv7e-m -mfpu=fpv4-sp-d16 -mfloat-abi=hard
+See the section above on Toolchains, NOTE 2, for explanations for some of
+the configuration settings. Some of the usual settings are just not supported
+by the "Lite" version of the Atollic toolchain.
STM32F4Discovery-specific Configuration Options
===============================================
diff --git a/nuttx/configs/stm32f4discovery/nsh/Make.defs b/nuttx/configs/stm32f4discovery/nsh/Make.defs
index 02dec9abf..60d264c50 100644
--- a/nuttx/configs/stm32f4discovery/nsh/Make.defs
+++ b/nuttx/configs/stm32f4discovery/nsh/Make.defs
@@ -56,8 +56,12 @@ ifeq ($(CONFIG_STM32_ATOLLIC),y)
CROSSDEV = arm-atollic-eabi-
ARCROSSDEV =
WINTOOL = y
+ifeq ($(CONFIG_ARCH_FPU),y)
+ ARCHCPUFLAGS = -mcpu=cortex-m4 -mthumb -march=armv7e-m -mfpu=fpv4-sp-d16 -mfloat-abi=hard
+else
ARCHCPUFLAGS = -mcpu=cortex-m3 -mthumb -mfloat-abi=soft
endif
+endif
ifeq ($(CONFIG_STM32_DEVKITARM),y)
# devkitARM under Windows
CROSSDEV = arm-eabi-
diff --git a/nuttx/configs/stm32f4discovery/ostest/Make.defs b/nuttx/configs/stm32f4discovery/ostest/Make.defs
index ea129c142..a59a108bc 100644
--- a/nuttx/configs/stm32f4discovery/ostest/Make.defs
+++ b/nuttx/configs/stm32f4discovery/ostest/Make.defs
@@ -56,8 +56,12 @@ ifeq ($(CONFIG_STM32_ATOLLIC),y)
CROSSDEV = arm-atollic-eabi-
ARCROSSDEV =
WINTOOL = y
+ifeq ($(CONFIG_ARCH_FPU),y)
+ ARCHCPUFLAGS = -mcpu=cortex-m4 -mthumb -march=armv7e-m -mfpu=fpv4-sp-d16 -mfloat-abi=hard
+else
ARCHCPUFLAGS = -mcpu=cortex-m3 -mthumb -mfloat-abi=soft
endif
+endif
ifeq ($(CONFIG_STM32_DEVKITARM),y)
# devkitARM under Windows
CROSSDEV = arm-eabi-