Skip to content

Commit 660a3d9

Browse files
committed
[cortex-m] Enable FPU before startup script
This allows the compiler to emit instructions that access the FPU registers for copying.
1 parent b4eddeb commit 660a3d9

File tree

3 files changed

+10
-7
lines changed

3 files changed

+10
-7
lines changed

src/modm/platform/core/cortex/module.lb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ def build(env):
293293
env.outbasepath = "modm/src/modm/platform/core"
294294

295295
# startup script
296-
env.copy("reset_handler.sx")
296+
env.template("reset_handler.sx.in")
297297
env.template("startup.c.in")
298298
env.template("vectors.c.in")
299299
env.collect(":build:linkflags", "-nostartfiles")

src/modm/platform/core/cortex/reset_handler.sx renamed to src/modm/platform/core/cortex/reset_handler.sx.in

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2019, Niklas Hauser
2+
* Copyright (c) 2019, 2021, Niklas Hauser
33
*
44
* This file is part of the modm project.
55
*
@@ -16,8 +16,16 @@
1616
.type Reset_Handler, %function
1717
.func Reset_Handler
1818
Reset_Handler:
19+
// Some bootloaders do not reset the stack pointer back to the VTOR entry
1920
ldr r0,=__main_stack_top
2021
mov sp,r0
22+
%% if with_fpu
23+
// Enable FPU early so the compiler may use FPU registers for copying
24+
// SCB->CPACR = ((3UL << 10*2) | (3UL << 11*2));
25+
ldr r0,=0xe000ed88
26+
ldr r1,=0x00f00000
27+
str r1, [r0, #0]
28+
%% endif
2129
bl __modm_initialize_platform
2230
bl modm_initialize_platform
2331
b __modm_startup

src/modm/platform/core/cortex/startup.c.in

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -102,11 +102,6 @@ void __modm_startup(void)
102102
SCB_EnableICache();
103103
%% endif
104104

105-
%% if with_fpu
106-
// Enable FPU in privileged and user mode
107-
SCB->CPACR |= ((3UL << 10*2) | (3UL << 11*2));
108-
%% endif
109-
110105
%% if "m0" not in core
111106
// Set the vector table location
112107
SCB->VTOR = (uint32_t)__vector_table_{{ vector_table_location }}_start;

0 commit comments

Comments
 (0)