Environment: LPC2378 (ARM7TDMI-S), GCC 4.3.2 (same with 4.2.2)
FreeRTOS mandates an ISR wrapper which:
- saves the task context
- calls the real handler
- restores/modifies the task context
In case there are local variables in the real handler, the wrapper has to issue an external call to the real handler because of stack preparation.
Without this call, one might run into an exception due to access beyond the memory limit.
It’s perfectly legal to declare both the wrapper and the real handler as static.
When compiling with optimization (-O2), GCC may inline static functions.
This will lead to the described behaviour.
There are two ways around this:
- declare the real handler as non-static
- prevent inlineing of the real handler
I’d opt for the second variant, as declaring local functions as static is part of good coding style.
GCC provides an attribute "noinline" to achieve this.
For a working example see below. To see the effect in real life, comment out the noinline attribute.
Mr. Barry, please include this in the documentation and/or as a FAQ.
Also I’d suggest to update the provided demo codes accordingly.
Most of the demos use the non-static approach (all for ARM7).
static void xHandler(void) __attribute__ ((noinline));
static void xHandler(void)
volatile u32 a;
volatile u32 b;
a = 1;
b = 1;
static void xISR(void) __attribute__ ((naked));
static void xISR(void)
/* Save the context of the interrupted task. */
/* Call the handler. This must be a separate function from the wrapper
to ensure the correct stack frame is set up. */
/* Restore the context of whichever task is going to run next. */