summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--build_rules22
-rw-r--r--cortex_m/fpu.h20
-rw-r--r--startup/entry.cpp6
3 files changed, 38 insertions, 10 deletions
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 <stdint.h>
+
+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 <stdint.h>
#include <rcc/rcc.h>
+#include <cortex_m/fpu.h>
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;