From c504494a3d42112be728d6aca35e48bc13786211 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mario=20H=C3=BCttel?= Date: Sun, 30 Aug 2020 19:40:08 +0200 Subject: [PATCH] Fix possible hardfault when optimizing code --- startup/startup_stm32f407vx.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/startup/startup_stm32f407vx.c b/startup/startup_stm32f407vx.c index 71a3d80..19199e3 100644 --- a/startup/startup_stm32f407vx.c +++ b/startup/startup_stm32f407vx.c @@ -280,9 +280,23 @@ extern unsigned int __ld_ebss; extern unsigned int __ld_sheap; extern unsigned int __ld_eheap; +#ifdef CPACR +#undef CPACR +#endif + +#define CPACR (*((volatile uint32_t *)0xE000ED88)) + void Reset_Handler(void) { /* Stack is already initialized by hardware */ + /* The first thing we do here, is to initialize the FPU + * When this code is compiled optimized with hardfpu abi, + * GCC tends to generate FPU instructions for data copying + */ +#if __FPU_USED == 1 + CPACR |= (0xF << 20); +#endif + /* Copy .data section */ __init_section(&__ld_load_data, &__ld_sdata, &__ld_edata); /* Fill bss with zero */