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"
#define VECTORTABLE_SIZE (240)
#define VECTORTABLE_ALIGNMENT (0x100U)
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] = __VECTOR_TABLE[i];
}
vectorTable_RAM[
SysTick_IRQn + 16] = (uint32_t)SysTick_Handler_RAM;
SCB->VTOR = (uint32_t)&vectorTable_RAM;
while(1);
}