Enable FPU for STM32F3

Hi, I’m having trouble enabling the FPU on stem32f3. The problem is, when I include some float point computation in my code, e.g., strtof and sqrt, the program will crash. I used a st-link debugger to log the executed instructions and found out that the program executes until it encounters a float point instruction (e.g. vpush, vmov), then stuck at a UsageFault_Handler InfiniteLoop. see below:

Then I googled and found out this to be most likely due to FPU not enabled. So I followed this tutorial, however for step 4, I cannot find the definition of the function SystemInit for the board stm32f3. I only found the declaration of it in hal/stm32f3/device/system_stm32f3xx.h:
extern
and it is called in hal/stm32f3/stm32f3_startup.S:
bl
weak

So what sould I do?


I did see that for some development board this is well defined:
efm32tg11b

Hi,

The HAL for the STM chips is pretty heavily modified to avoid having to drag around the whole library. I’m guessing SystemInit got pulled out during that process. Try defining the following function somewhere:

void SystemInit(void)
{
    SCB->CPACR |= ((3UL << 10*2)|(3UL << 11*2));  /* set CP10 and CP11 Full Access */
}

Pulled from https://github.com/STMicroelectronics/STM32CubeF3/blob/8fa3aadf0255818f0ca72ba6a5a6731ef8c585fb/Drivers/CMSIS/Device/ST/STM32F3xx/Source/Templates/system_stm32f3xx.c

I eventually came up with the following solution:

  1. locate firmware/hal/stm32f3/stm32f3_startup.S
  2. add the following code between bcc FillZerobss and bl SystemInit:
    LDR.W R0, =0xE000ED88
    LDR R1, [R0]
    ORR R1, R1
    STR R1, [R0]

Hi, sorry to bother.
I want to enable the FPU on STM32F3 too and I follow your guide here :
image

But I got the error like:

Could you tell me what should I do then?

Hi,

I find there a error in your code, is it suppose to be

ORR R1, R1, #(0xf << 20)

?
which is equal to Alex’s reply.