CMSIS-Core (Cortex-M)  Version 5.3.0
CMSIS-Core support for Cortex-M processor-based devices
 All Data Structures Files Functions Variables Enumerations Enumerator Groups Pages
Using Interrupt Vector Remap

Most Cortex-M processors provide VTOR register for remapping interrupt vectors. The following example shows a typical use case where the interrupt vectors are copied to RAM and the SysTick_Handler is replaced.

#include "ARMCM3.h" // Device header
#define VECTORTABLE_SIZE (240) /* size of the used vector tables */
/* see startup file startup_ARMCM3.c */
#define VECTORTABLE_ALIGNMENT (0x100U) /* 16 Cortex + 32 ARMCM3 = 48 words */
/* next power of 2 = 256 */
/* externals from startup_ARMCM3.c */
extern uint32_t __VECTOR_TABLE[VECTORTABLE_SIZE]; /* vector table ROM */
/* new vector table in RAM, same size as vector table in ROM */
uint32_t vectorTable_RAM[VECTORTABLE_SIZE] __attribute__(( aligned (VECTORTABLE_ALIGNMENT) ));
/*----------------------------------------------------------------------------
SysTick_Handler
*----------------------------------------------------------------------------*/
volatile uint32_t msTicks = 0; /* counts 1ms timeTicks */
void SysTick_Handler(void) {
msTicks++; /* increment counter */
}
/*----------------------------------------------------------------------------
SysTick_Handler (RAM)
*----------------------------------------------------------------------------*/
volatile uint32_t msTicks_RAM = 0; /* counts 1ms timeTicks */
void SysTick_Handler_RAM(void) {
msTicks_RAM++; /* increment counter */
}
/*----------------------------------------------------------------------------
MAIN function
*----------------------------------------------------------------------------*/
int main (void) {
uint32_t i;
for (i = 0; i < VECTORTABLE_SIZE; i++) {
vectorTable_RAM[i] = __VECTOR_TABLE[i]; /* copy vector table to RAM */
}
/* replace SysTick Handler */
vectorTable_RAM[SysTick_IRQn + 16] = (uint32_t)SysTick_Handler_RAM;
/* relocate vector table */
SCB->VTOR = (uint32_t)&vectorTable_RAM;
__DSB();
SystemCoreClockUpdate(); /* Get Core Clock Frequency */
SysTick_Config(SystemCoreClock / 1000ul); /* Setup SysTick Timer for 1 msec */
while(1);
}