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"
extern uint32_t __Vectors[];
#define VECTORTABLE_SIZE (256)
#define VECTORTABLE_ALIGNMENT (0x100ul)
uint32_t vectorTable_RAM[VECTORTABLE_SIZE] __attribute__(( aligned (VECTORTABLE_ALIGNMENT) ));
volatile uint32_t msTicks = 0;
void SysTick_Handler(void) {
msTicks++;
}
volatile uint32_t msTicks_RAM = 0;
void SysTick_Handler_RAM(void) {
msTicks_RAM++;
}
int main (void) {
uint32_t i;
for (i = 0; i < VECTORTABLE_SIZE; i++) {
vectorTable_RAM[i] = __Vectors[i];
}
vectorTable_RAM[
SysTick_IRQn + 16] = (uint32_t)SysTick_Handler_RAM;
SCB->VTOR = (uint32_t)&vectorTable_RAM;
while(1);
}