Skip to content

Commit 7a15854

Browse files
committed
Merge pull request #93 from spectaclelabs/bugfix-STM32-vectors
Make STM32F4 vectors relocate properly
2 parents 544ac9e + 6ae1e9e commit 7a15854

File tree

1 file changed

+4
-2
lines changed
  • libraries/mbed/targets/cmsis/TARGET_STM/TARGET_STM32F4XX

1 file changed

+4
-2
lines changed

libraries/mbed/targets/cmsis/TARGET_STM/TARGET_STM32F4XX/cmsis_nvic.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,22 @@
66
#include "cmsis_nvic.h"
77

88
#define NVIC_RAM_VECTOR_ADDRESS (0x20000000) // Location of vectors in RAM
9-
#define NVIC_FLASH_VECTOR_ADDRESS (0x0) // Initial vector position in flash
9+
10+
static unsigned char vtor_relocated;
1011

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

1516
// Copy and switch to dynamic vectors if the first time called
16-
if (SCB->VTOR == NVIC_FLASH_VECTOR_ADDRESS) {
17+
if (!vtor_relocated) {
1718
uint32_t *old_vectors = vectors;
1819
vectors = (uint32_t*)NVIC_RAM_VECTOR_ADDRESS;
1920
for (i=0; i<NVIC_NUM_VECTORS; i++) {
2021
vectors[i] = old_vectors[i];
2122
}
2223
SCB->VTOR = (uint32_t)NVIC_RAM_VECTOR_ADDRESS;
24+
vtor_relocated = 1;
2325
}
2426
vectors[IRQn + 16] = vector;
2527
}

0 commit comments

Comments
 (0)