This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

floating point inside an ISR

We have an application where we need to do some basic floating point operations within an interrupt. I am aware that this is not the most desirable practice, but, my question is, does the compiler create code that is safe/mutually exclusive in respect of the FPU.

We are using the STM32F4 running at 168MHz; an external interrupt occurs at 133kHz, at which point we read some external variables, do some floating point multiplies and add them to accumulators. In the main loop we periodically do some math on the accumulated data that takes aprox 330mS. The interrupt duty cycle is - 2.2uS in interrupt, - 5.3uS in main, so there is a high probability that floating point operations will occur 'concurrently'.

Is there a danger that the floating point operations carried out by the ISR could be corrupted by operations carried out by the main,

Regards
Konrad

Parents
  • I'm not really sure how the compiler handles floating-point in the ISR.

    But floating-point or not, you still need to consider atomicity - i.e. how to make sure that the main loop doesn't read one half of a variable and then gets interrupted by the ISR and then after the ISR ends reads the second half of the variable - a variable that has now been modified by the ISR.

    Another thing: Is it really impossible or not practical to make use of fixed-point arithmetic in the ISR? 32 and 64-bit integers can represent quite a number of value digits of a non-integer value.

Reply
  • I'm not really sure how the compiler handles floating-point in the ISR.

    But floating-point or not, you still need to consider atomicity - i.e. how to make sure that the main loop doesn't read one half of a variable and then gets interrupted by the ISR and then after the ISR ends reads the second half of the variable - a variable that has now been modified by the ISR.

    Another thing: Is it really impossible or not practical to make use of fixed-point arithmetic in the ISR? 32 and 64-bit integers can represent quite a number of value digits of a non-integer value.

Children