Skip to main content
Associate II
August 10, 2024
Solved

Using FPU in ISR and main() Code

  • August 10, 2024
  • 1 reply
  • 927 views

I want to use the FPU in an ISR. Will I have context switching issues or i have to specifically make changes in the System_stmxx.c if i am using code generated from CubeIDE.

Do i need to setup these registers explicitly or it is handled by CubeIDE by default? (i didn't found these bits explicitly setup in System_stmxxx.c )

 FPU->FPCCR |= (FPU_FPCCR_ASPEN_Msk | FPU_FPCCR_LSPEN_Msk);
This code sets the ASPEN (Automatic State Preservation Enable) and LSPEN (Lazy State Preservation Enable) bits, ensuring that the FPU context is handled appropriately during interrupts.

MCU: STM32H723ZGT6
CubeIDE Ver: 1.16.0
    Best answer by TDK

    Those two bits are set by default, so no explicit setup is needed.

    There are no other issues or special considerations you need to make to get this to work. When the first FPU instruction is used within an ISR, the FPU registers are pushed onto the stack. This is handled by the core. You'll lose some cpu cycles due to this, but the program will function as intended.

    1 reply

    TDK
    TDKBest answer
    Super User
    August 10, 2024

    Those two bits are set by default, so no explicit setup is needed.

    There are no other issues or special considerations you need to make to get this to work. When the first FPU instruction is used within an ISR, the FPU registers are pushed onto the stack. This is handled by the core. You'll lose some cpu cycles due to this, but the program will function as intended.

    "If you feel a post has answered your question, please click ""Accept as Solution""."