Get interrupt execution status on Cortex-M processors

You might come to a situation when you wanna know if current code is executing inside interrupt or not. This might be handy when you do a library and you have one function which you wanna call in interrupt handler for specific event or without interrupt handler, buf wanna execute something specific in function only if you are currently in interrupt. You can create 2 different functions of course, but what if you have one very big function, and for example when you are in interrupt, you wanna just do something small inside function somewhere at the middle?

Then you wanna know if you are executing code within interrupt or not. Cortex-M processors have special section SCB (System Control Block) inside. ICSR (Interrupt Control and State Register) register inside this section can be used to detect, if there is currently active any interrupt handler or not. Below is image of ICSR register for Cortex-M4 processor (Have in mind that all Cortex-M processors uses bottom 9 bits to detect proper interrupt number currently executing).

ARM Cortex-M SCB ICSR register structure. From

ARM Cortex-M SCB ICSR register structure. From

VECTACTIVE bits of ICSR register told us which interrupt is active, it’s value is as follow:

  • 0: Interrupt is not active, we are in thread mode
  • > 0: Interrupt is active, not in thread mode

So, the idea is to read this bits from register and if result is more than zero, we are currently executing from interrupt source.


Bottom example runs on STM32F401-Nucleo board and shows principle how to check if current execution is inside interrupt or not. It calls the same function inside interrupt and in main function (thread mode).

Result after some time

Result after some time



Owner of this site. Also electronic enthusiasts, web developer, 3D printer fan, handball player and more. Big fan of STM32F4 devices. In anticipation of the new Discovery board for STM32F7 lines.

You may also like...

Read before commenting!

Before you make a new comment, make sure you agree with things listed below:

  • - Read post to make sure if it is already posted what you are asking for,
  • - Make sure you have the latest version of libraries used in your project,
  • - Make a clean and grammatically correct written message,
  • - Report as many details as possible, including what have you done so far,
  • - Do NOT post any code here. Use Pastebin,
  • - Do NOT post any error codes here. Use Pastebin,
  • - Specify STM32Fxxx family and used Discovery/EVAL/Nucleo or custom made board,
  • - Make sure your clock is set correct for PLL,
  • - If you are using my HAL drivers, please check this post how to start.
Comment will be deleted on breaking these rules without notification!