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
/* externals from startup_ARMCM3.s */
extern uint32_t __Vectors[]; /* vector table ROM */
#define VECTORTABLE_SIZE (256) /* size Cortex-M3 vector table */
#define VECTORTABLE_ALIGNMENT (0x100ul) /* 16 Cortex + 32 ARMCM3 = 48 words */
/* next power of 2 = 256 */
/* new vector table in RAM */
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] = __Vectors[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);
}