From 14409cd7fd6bc903a9cf87c3dccbc854e895033d Mon Sep 17 00:00:00 2001 From: Bogdan Marinescu Date: Mon, 29 Jul 2013 18:13:37 +0300 Subject: [PATCH] Change the check for vector table relocation Allows the user to specify his own VTOR location. Fixes PRMBED-1065. --- .../cmsis/TARGET_Freescale/TARGET_KL05Z/cmsis_nvic.c | 3 ++- .../cmsis/TARGET_Freescale/TARGET_KL25Z/cmsis_nvic.c | 3 ++- .../targets/cmsis/TARGET_NXP/TARGET_LPC13XX/cmsis_nvic.c | 3 ++- .../targets/cmsis/TARGET_NXP/TARGET_LPC176X/cmsis_nvic.c | 3 ++- .../targets/cmsis/TARGET_NXP/TARGET_LPC408X/cmsis_nvic.c | 3 ++- .../targets/cmsis/TARGET_NXP/TARGET_LPC43XX/cmsis_nvic.c | 8 +++++++- .../targets/cmsis/TARGET_NXP/TARGET_LPC81X/cmsis_nvic.c | 3 ++- .../cmsis/TARGET_STM/TARGET_STM32F4XX/cmsis_nvic.c | 3 ++- 8 files changed, 21 insertions(+), 8 deletions(-) diff --git a/libraries/mbed/targets/cmsis/TARGET_Freescale/TARGET_KL05Z/cmsis_nvic.c b/libraries/mbed/targets/cmsis/TARGET_Freescale/TARGET_KL05Z/cmsis_nvic.c index b8a3e09011..f778acee50 100644 --- a/libraries/mbed/targets/cmsis/TARGET_Freescale/TARGET_KL05Z/cmsis_nvic.c +++ b/libraries/mbed/targets/cmsis/TARGET_Freescale/TARGET_KL05Z/cmsis_nvic.c @@ -7,13 +7,14 @@ #define NVIC_NUM_VECTORS (16 + 32) // CORE + MCU Peripherals #define NVIC_RAM_VECTOR_ADDRESS (0x1FFFFC00) // Vectors positioned at start of RAM +#define NVIC_FLASH_VECTOR_ADDRESS (0x0) // Initial vector position in flash void NVIC_SetVector(IRQn_Type IRQn, uint32_t vector) { static volatile uint32_t *vectors = (uint32_t*)NVIC_RAM_VECTOR_ADDRESS; uint32_t i; // Copy and switch to dynamic vectors if the first time called - if (SCB->VTOR != NVIC_RAM_VECTOR_ADDRESS) { + if (SCB->VTOR == NVIC_FLASH_VECTOR_ADDRESS) { uint32_t *old_vectors = (uint32_t*)SCB->VTOR; for (i=0; iVTOR != NVIC_RAM_VECTOR_ADDRESS) { + if (SCB->VTOR == NVIC_FLASH_VECTOR_ADDRESS) { uint32_t *old_vectors = (uint32_t*)SCB->VTOR; for (i=0; iVTOR != NVIC_RAM_VECTOR_ADDRESS) { + if (SCB->VTOR == NVIC_FLASH_VECTOR_ADDRESS) { uint32_t *old_vectors = (uint32_t*)SCB->VTOR; for (i=0; iVTOR != NVIC_RAM_VECTOR_ADDRESS) { + if (SCB->VTOR == NVIC_FLASH_VECTOR_ADDRESS) { uint32_t *old_vectors = (uint32_t*)SCB->VTOR; for (i=0; iVTOR != NVIC_RAM_VECTOR_ADDRESS) { + if (SCB->VTOR == NVIC_FLASH_VECTOR_ADDRESS) { uint32_t *old_vectors = (uint32_t*)SCB->VTOR; for (i=0; iVTOR != NVIC_RAM_VECTOR_ADDRESS) { + if (!vtor_relocated) { uint32_t *old_vectors = (uint32_t*)SCB->VTOR; for (i=0; iVTOR = (uint32_t)vectors; + vtor_relocated = 1; } vectors[IRQn + 16] = vector; diff --git a/libraries/mbed/targets/cmsis/TARGET_NXP/TARGET_LPC81X/cmsis_nvic.c b/libraries/mbed/targets/cmsis/TARGET_NXP/TARGET_LPC81X/cmsis_nvic.c index 6290fa6003..a58325836d 100644 --- a/libraries/mbed/targets/cmsis/TARGET_NXP/TARGET_LPC81X/cmsis_nvic.c +++ b/libraries/mbed/targets/cmsis/TARGET_NXP/TARGET_LPC81X/cmsis_nvic.c @@ -7,13 +7,14 @@ #define NVIC_NUM_VECTORS (16 + 32) // CORE + MCU Peripherals #define NVIC_RAM_VECTOR_ADDRESS (0x10000000) // Vectors positioned at start of RAM +#define NVIC_FLASH_VECTOR_ADDRESS (0x0) // Initial vector position in flash void NVIC_SetVector(IRQn_Type IRQn, uint32_t vector) { static volatile uint32_t* vectors = (uint32_t*)NVIC_RAM_VECTOR_ADDRESS; int i; // Copy and switch to dynamic vectors if first time called - if (SCB->VTOR != NVIC_RAM_VECTOR_ADDRESS) { + if (SCB->VTOR == NVIC_FLASH_VECTOR_ADDRESS) { uint32_t *old_vectors = (uint32_t*)SCB->VTOR; for (i=0; iVTOR != NVIC_RAM_VECTOR_ADDRESS) { + if (SCB->VTOR == NVIC_FLASH_VECTOR_ADDRESS) { uint32_t *old_vectors = (uint32_t*)SCB->VTOR; for (i=0; i