CMSIS-Core (Cortex-M)  
CMSIS-Core support for Cortex-M processor-based devices
 
Loading...
Searching...
No Matches
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);
}
void __enable_irq(void)
Globally enables interrupts and configurable fault handlers.
void __disable_irq(void)
Globally disables interrupts and configurable fault handlers.
@ SysTick_IRQn
Exception 15: System Tick Interrupt.
Definition: Ref_NVIC.txt:398
uint32_t SysTick_Config(uint32_t ticks)
System Tick Timer Configuration.
#define __VECTOR_TABLE
Symbol name used for the (static) interrupt vector table.
Definition: Ref_CompilerControl.txt:531
void __DSB(void)
Data Synchronization Barrier.
uint32_t SystemCoreClock
Variable to hold the system core clock value.
Definition: Ref_SystemAndClock.txt:68
void SystemCoreClockUpdate(void)
Function to update the variable SystemCoreClock.