# How to disable interrupt on Cortex M

**URL:** <https://forums.freertos.org/t/how-to-disable-interrupt-on-cortex-m/10046>\
**Category:** Kernel\
**Created:** [June 16, 2020, 8:24am UTC](https://forums.freertos.org/t/how-to-disable-interrupt-on-cortex-m/10046 "2020-06-16T08:24:32Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![mastupristi](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/mastupristi/32/503_2.png) [@mastupristi](https://forums.freertos.org/u/mastupristi)\
**Post date:** [June 16, 2020, 8:24am UTC](https://forums.freertos.org/t/how-to-disable-interrupt-on-cortex-m/10046/1 "2020-06-16T08:24:32Z")

</div>

When I want to disable interrupt on Cortex M core I have more choice.  
can you describe (even roughly) the difference between `taskDISABLE_INTERRUPTS()` and `__disable_irq()`?

They are defined as follow:

```
/**
 * task. h
 *
 * Macro to disable all maskable interrupts.
 *
 * \defgroup taskDISABLE_INTERRUPTS taskDISABLE_INTERRUPTS
 * \ingroup SchedulerControl
 */
#define taskDISABLE_INTERRUPTS()	portDISABLE_INTERRUPTS()

#define portDISABLE_INTERRUPTS()	vPortRaiseBASEPRI()

portFORCE_INLINE static void vPortRaiseBASEPRI( void )
{
uint32_t ulNewBASEPRI;

	__asm volatile
	(
		"	mov %0, %1 \n"	\
		"	msr basepri, %0 \n" \
		"	isb \n" \
		"	dsb \n" \
		:"=r" (ulNewBASEPRI) : "i" ( configMAX_SYSCALL_INTERRUPT_PRIORITY ) : "memory"
	);
}

/**
  \brief Disable IRQ Interrupts
  \details Disables IRQ interrupts by setting the I-bit in the CPSR.
	   Can only be executed in Privileged modes.
 */
__STATIC_FORCEINLINE void__ disable_irq(void)
{
  __ASM volatile ("cpsid i" : : : "memory");
}

```

Also `taskENTER_CRITICAL()` uses `portDISABLE_INTERRUPTS()`. So if I need to disable interruptions can I feel free to use `taskDISABLE_INTERRUPTS()` or should I use `taskENTER_CRITICAL()`?

best regards  
Max

---

<div class="post-metadata">

**Author:** ![richard-damon](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/richard-damon/32/38_2.png) [@richard-damon](https://forums.freertos.org/u/richard-damon)\
**Post date:** [June 16, 2020, 11:41am UTC](https://forums.freertos.org/t/how-to-disable-interrupt-on-cortex-m/10046/2 "2020-06-16T11:41:34Z")

</div>

There are at least two fundamental ways on the Cortex-M series to ‘Disable Interrupts’, The method used by taskENTER\_CRITICAL / portENTER\_CRITICAL / portDISABLE\_INTERRUPTS / vPortRaiseBASEPRI() doesn’t actually disable ALL interrupts, but only those interrupts that can interact with FreeRTOS, but leaves any higher priority interrupts enabled. This allows the FreeRTS kernel to work with its core variables and not get sidetracked with another operation that needs them. It also allows for any very urgent operations the program may have to continue. The difference between the ENTER\_CRITICAL and DISABLE\_INTERRUPTS is that the critical section routines handle possible nesting, while the disable interrupts is a bit faster but assumes no nesting.

The second method, used by \_\_disable\_irq() actually turns off the whole IRQ system, so blocking even those possibly ultra urgent ISRs that don’t interact with FreeRTOS. I don’t think FreeRTOS ever calls this, but the application can if it needs a short critical section protected even from those interrupts for its own needs.

---

<div class="post-metadata">

**Author:** ![mastupristi](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/mastupristi/32/503_2.png) [@mastupristi](https://forums.freertos.org/u/mastupristi)\
**Post date:** [June 16, 2020, 12:47pm UTC](https://forums.freertos.org/t/how-to-disable-interrupt-on-cortex-m/10046/3 "2020-06-16T12:47:14Z")

</div>

I’m going to disable interrupts in the `configASSERT()` implementation.

---

<div class="post-metadata">

**Author:** ![richard-damon](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/richard-damon/32/38_2.png) [@richard-damon](https://forums.freertos.org/u/richard-damon)\
**Post date:** [June 16, 2020, 12:59pm UTC](https://forums.freertos.org/t/how-to-disable-interrupt-on-cortex-m/10046/4 "2020-06-16T12:59:11Z")

</div>

That probably wants \_\_disable\_irq(), but portDISABLE\_INTERRUPTS() may also be good enough, it really depends on what you need done with the ultra high priority interrupts (if you have any),
