5

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)?
filo
  • 8,801
  • 1
  • 25
  • 46
  • 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. – jonk May 02 '17 at 16:39

2 Answers2

7

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.

Fabien
  • 86
  • 1
  • 2
  • I think I've found the exact description http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.dui0497a/BABDGADF.html – filo Mar 22 '18 at 09:04
1

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.

Dave Tweed
  • 168,369
  • 17
  • 228
  • 393
Richard
  • 401
  • 2
  • 1
  • 1
    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. – filo May 02 '17 at 18:17