Skip to content

Commit

Permalink
Merge pull request #93 from spectaclelabs/bugfix-STM32-vectors
Browse files Browse the repository at this point in the history
Make STM32F4 vectors relocate properly
  • Loading branch information
emilmont committed Oct 25, 2013
2 parents 544ac9e + 6ae1e9e commit 7a15854
Showing 1 changed file with 4 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,22 @@
#include "cmsis_nvic.h"

#define NVIC_RAM_VECTOR_ADDRESS (0x20000000) // Location of vectors in RAM
#define NVIC_FLASH_VECTOR_ADDRESS (0x0) // Initial vector position in flash

static unsigned char vtor_relocated;

void NVIC_SetVector(IRQn_Type IRQn, uint32_t vector) {
uint32_t *vectors = (uint32_t*)SCB->VTOR;
uint32_t i;

// Copy and switch to dynamic vectors if the first time called
if (SCB->VTOR == NVIC_FLASH_VECTOR_ADDRESS) {
if (!vtor_relocated) {
uint32_t *old_vectors = vectors;
vectors = (uint32_t*)NVIC_RAM_VECTOR_ADDRESS;
for (i=0; i<NVIC_NUM_VECTORS; i++) {
vectors[i] = old_vectors[i];
}
SCB->VTOR = (uint32_t)NVIC_RAM_VECTOR_ADDRESS;
vtor_relocated = 1;
}
vectors[IRQn + 16] = vector;
}
Expand Down

0 comments on commit 7a15854

Please sign in to comment.