I have FreeRTOS running on a MKE06 Cortex-M0+ (based on SAMD20 demo), GCC toolchain. I am trying to figure out optimal task stack sizes (with the help of avstack.pl).

I want to use only static memory allocation. In the FAQ I have read this:

The stack requirements of interrupt service routines - which for many RTOS ports is zero as the RTOS will switch to use a dedicated interrupt stack on entry to an interrupt service routine.

I use this port. I don't know much assembly, but I think I do not see anything that would configure stack pointer separately for the interrupts (is such thing even supported by M0+?). I allocated stack for the idle task manually (with vApplicationGetIdleTaskMemory), but I did not find a function to provide stack space for interrupts. Interrupts work fine, I do not use nested interrupts.

My questions:

  1. Should my task stack size be enlarged by at least the biggest possible interrupt stack size?
  2. Can I allocate a separate interrupt stack on Cortex M0+ in plain C (ie. without adding own assembly to each ISR)?
  • \$\begingroup\$ I honestly don't use FreeRTOS and the source you linked doesn't seem to include the code that would clarify it for me. But I do write my own (easy enough.) In mine, the interrupting event uses the current thread stack. (I usually don't support full-blown processes, as it is rarely needed in embedded systems I work on.) Although I can technically (it's rare) support multiple interrupts, it's guaranteed that no more than one interrupting event will ever occur on any one thread stack. I almost never set up a separate dedicated stack. But your FAQ does say this is port-dependent here. \$\endgroup\$ – jonk May 2 '17 at 16:39

Interrupt service routine will use the stack you are also using for main(). You have a stack defined in your linker script, this is the one used for main and ISR, separate from the stack of the FreeRTOS tasks.


When a Cortex-M0 device accepts an interrupt it automatically switches to use a different stack, so interrupts do not use any of the task's stack.

Make sure you use a stack overflow hook (http://www.freertos.org/Stacks-and-stack-overflow-checking.html) in case you get the size to small, and monitor actual stack usage (http://www.freertos.org/uxTaskGetStackHighWaterMark.html) to ensure you are not allocating too much.

  • 1
    \$\begingroup\$ Where exactly is the interrupts stack located in my memory and how can I check its size? I thought an interrupt will use whichever stack is currently set, not its own. I know the overflow checking feature. \$\endgroup\$ – filo May 2 '17 at 18:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.