Skip to content

Interrupt handling

Felipe Torrezan edited this page Aug 28, 2023 · 1 revision

There are some differences to keep in mind when dealing with interrupt handling routines created for the GCC in the IAR toolchain.

The IAR C/C++ Compiler provides interrupt control functionality via the intrinsics header file which is shipped with the product.

#include <intrinsics.h>

Global interrupt control

The intrinsic header provide wrappers for GCC's global interrupt control:

#define __disable_irq __iar_builtin_disable_irq
#define __enable_irq __iar_builtin_enable_irq

Vector table

The interrupt vector table is usually set in a startup_<device>.s file as a public symbol. For example, when the target is a Cortex-M device:

        SECTION .intvec:CODE:NOROOT(2)
        PUBLIC  __vector_table
        DATA
__vector_table
        DCD     sfe(CSTACK)
        DCD     Reset_Handler             ; Reset Handler

        DCD     NMI_Handler               ; NMI Handler
        DCD     HardFault_Handler         ; Hard Fault Handler
        DCD     MemManage_Handler         ; MPU Fault Handler
        DCD     BusFault_Handler          ; Bus Fault Handler
        DCD     UsageFault_Handler        ; Usage Fault Handler
        DCD     0                         ; Reserved
        DCD     0                         ; Reserved
        DCD     0                         ; Reserved
        DCD     0                         ; Reserved
        DCD     SVC_Handler               ; SVCall Handler
        DCD     DebugMon_Handler          ; Debug Monitor Handler
        DCD     0                         ; Reserved
        DCD     PendSV_Handler            ; PendSV Handler
        DCD     SysTick_Handler           ; SysTick Handler

         ; Peripheral interrupt handlers
        DCD     Watchdog_Handler          ; Watchdog handler
        DCD     Foo_Handler               ; Foo handler
        ;;;; Remainder of the vector table

Interrupt handlers

The IAR C/C++ Compiler offers a multitude of different ways to work with interrupts and exceptions. The GCC interrupt handlers need to be updated to conform with IAR:

GCC IAR
Syntax
void foo(void)__attribute__((interrupt("Foo_Handler"))    
{ /* code */ }
__interrupt void Foo_Handler(void)    
{ /* code */ }