17.2.1 Interrupt Attribute
The
interrupt
attribute tells the compiler that the function is
an interrupt handler. Use of this attribute is optional when building interrupt handlers
for Cortex-M devices, but it is recommended to ensure that the compiler generates code
to align the stack pointer on an 8 byte boundary upon function entry. This attribute is
mandatory when writing interrupt handlers for Cortex-A devices, as the compiler must
generate context switch code for interrupt handlers on such devices. For
example:void __attribute__((interrupt)) hoppy (void)
{
// interrupt code goes here
}
When programming in C++, the interrupt handler symbol must be allocated to the C
namespace, which can be accomplished using
extern "C"
with the
definition, for example:extern "C"
void __attribute__((interrupt)) hoppy (void)
{
// interrupt code goes here
}
Note: The
interrupt
attribute can take arguments, as described in the GCC manual, but are ignored when targeting devices with a Cortex-M core.