‎2020-04-05 02:06 PM
Hi,
i am using stm32F411 and generate programs with cubeMX.
now I want to use the FPU in main and in interrupt context. Is it possible to use the FPU in interrupt context?
I do not know how CubeMX generated programs handle the FPU context save within interrupt.
‎2020-04-05 02:34 PM
> Is it possible to use the FPU in interrupt context?
Yes.
> I do not know how CubeMX generated programs handle the FPU context save within interrupt.
The processor handles it, and in a rather clever way:
https://static.docs.arm.com/dai0298/a/DAI0298A_cortex_m4f_lazy_stacking_and_context_switching.pdf
JW
‎2020-04-05 03:45 PM
thanks.
I had a quick view on the paper.
If I use the FPU in an interrupt routine 16 floating point register will be saved on the stack and popped if the routine returns. So that will cost minimum 32 cycles mor than a routine without using the FPU. Is that right?
‎2020-04-05 08:12 PM
> So that will cost minimum 32 cycles mor than a routine without using the FPU.
Yep. And more RAM reserved for stack. Everything has its price.
-- pa
‎2020-04-06 05:30 AM
>Yep. And more RAM reserved for stack. Everything has its price.
easy to pay for me. i have about 10000 multiplications every millisecond. ;)
FPU saves a lot of time in this case, because 1 have one fp mult instead of an integer mult and a shift operation.
thx
‎2022-12-28 04:01 AM
The answer is that there is no FPU context control, and the user must implement in code.
Sadly, and I mean sadly, despite 10 years of posts like yours, STM staff have still not bother to post a code snippet to show how this is done.
If you dig through the RTOS source code you can extract their method.
I am pushing STM to post a routine to handle this efficiently, though as no one replied to your post in 2 years, you probably found a solution or changed to another supplier.
‎2022-12-28 04:19 AM
In the past, float was discouraged in mobile amd linux within interrupts, and a mitigation using Q31 format was introduced (fractional bit format amd arithmetics). Wondering if things have improved since then... Cordic and FMAT are hw ip separated from core to accelerate computation for motor, etc...
‎2022-12-28 04:52 AM
Cortex-M arch has special optimizations for hardware FP. Very clever and convenient, as Jan wrote.
FPU_IRQ does not work for some STM32's, this is in errata.
‎2022-12-28 05:22 AM
I looked at the F407 errata and I didn't see mention of FPU not working in IRQs.
Lazy context doesn't work reliably, and STM are yet to publish an efficient routine to handle FPU context saving and restoring, though I have asked several times.
STM staff publishing an FPU context routine would close this matter for once and all.