From 8419b87c6bd7be468239d0f68155631dfb5db103 Mon Sep 17 00:00:00 2001 From: Vegard Storheil Eriksen Date: Mon, 31 Dec 2012 13:55:56 +0100 Subject: Fixed FPU support. Selecting proper FPU flags in build_rules and enabling FPU during startup. --- build_rules | 22 ++++++++++++---------- cortex_m/fpu.h | 20 ++++++++++++++++++++ startup/entry.cpp | 6 ++++++ 3 files changed, 38 insertions(+), 10 deletions(-) create mode 100644 cortex_m/fpu.h diff --git a/build_rules b/build_rules index 385fde1..a6d8899 100644 --- a/build_rules +++ b/build_rules @@ -14,17 +14,17 @@ def select_arm(env, family): has_mcu = False env.Replace( - CC = '${TOOLCHAIN}gcc', - CXX = '${TOOLCHAIN}g++', - AS = '${TOOLCHAIN}gcc', - LINK = '${TOOLCHAIN}gcc', - AR = '${TOOLCHAIN}ar', + CC = '${TOOLCHAIN}gcc', + CXX = '${TOOLCHAIN}g++', + AS = '${TOOLCHAIN}gcc', + LINK = '${TOOLCHAIN}gcc', + AR = '${TOOLCHAIN}ar', RANLIB = '${TOOLCHAIN}ranlib', - CCFLAGS = '-O2 -Wall -ggdb -mcpu=${CPU_FAMILY} -mthumb -ffunction-sections', - CXXFLAGS = '-std=c++11 -fno-exceptions -fno-rtti -Wno-pmf-conversions', - ASFLAGS = '-c -x assembler-with-cpp -mcpu=${CPU_FAMILY} -mthumb', - LINKFLAGS = '-Wall -mcpu=${CPU_FAMILY} -mthumb -mhard-float -nostartfiles -Wl,-T${LINK_SCRIPT} -Wl,--gc-sections', + CCFLAGS = Split('-O2 -Wall -ggdb -mcpu=${CPU_FAMILY} -mthumb -ffunction-sections'), + CXXFLAGS = Split('-std=c++11 -fno-exceptions -fno-rtti -Wno-pmf-conversions'), + ASFLAGS = Split('-c -x assembler-with-cpp -mcpu=${CPU_FAMILY} -mthumb'), + LINKFLAGS = Split('-Wall -mcpu=${CPU_FAMILY} -mthumb -nostartfiles -Wl,-T${LINK_SCRIPT} -Wl,--gc-sections'), CPPPATH = [laks_dir], LIBPATH = [ld_dir], @@ -35,7 +35,9 @@ def select_arm(env, family): ) if has_mcu: - env.Append(CCFLAGS = ' -mhard-float') + env.Append(CCFLAGS = Split('-mfloat-abi=hard -mfpu=fpv4-sp-d16')) + env.Append(LINKFLAGS = Split('-mfloat-abi=hard -mfpu=fpv4-sp-d16')) + env.Append(CPPDEFINES = ['HAS_FPU']) def select_stm32(env, variant): family = variant[5:9] diff --git a/cortex_m/fpu.h b/cortex_m/fpu.h new file mode 100644 index 0000000..e5d4872 --- /dev/null +++ b/cortex_m/fpu.h @@ -0,0 +1,20 @@ +#ifndef FPU_H +#define FPU_H + +#include + +struct COPROC_t { + volatile uint32_t CPAC; +}; + +static COPROC_t& COPROC = *(COPROC_t*)0xe000ed88; + +struct FPU_t { + volatile uint32_t FPCC; + volatile uint32_t FPCA; + volatile uint32_t FPDSC; +}; + +static FPU_t& FPU = *(FPU_t*)0xe000ef34; + +#endif diff --git a/startup/entry.cpp b/startup/entry.cpp index d7385f8..64aac37 100644 --- a/startup/entry.cpp +++ b/startup/entry.cpp @@ -1,5 +1,6 @@ #include #include +#include int main(); @@ -35,6 +36,11 @@ void __attribute__((naked)) entry() { *wp++ = 0; } + // Enable FPU before calling any functions that can invoke FPU instructions. + #ifdef HAS_FPU + COPROC.CPAC |= (3 << 22) | (3 << 20); + #endif + // Call constructors. funcp_t* fp = &_init_array_start; -- cgit v1.2.3